Linux command line directory commands

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

danielmapar/LinuxCommandLine

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

  • date : current date
  • cal : current months calendar
  • cal 1999 : calendar for 1999
  • cal -3 : calendar (last month, current and next month)
  • cal -y : all year calendar
  • clear : clear console text
  • exit : exits de terminal

Screenshot

  • bin: binary (commands and utilities that all users can run)
  • sbin: this directory contains programs that performs vital system tasks (network management, disk partitioning). Only the superuser has access to these programs.
  • home: each user is given a directory under the home directory. A user can store anything in his home directory
  • opt: optional (additional software)
  • tmp: temporary files, files created by various programs (Generally cleared on reboot)
  • var: variable data, data that frequently changes over time.
    • Log files
    • Data bases
    • User mail
    • Spools -> temporary storage location
      • /var/spool is traditionally used for machine-local data being spooled to or from UNIX subsystems. For example, print jobs are spooled here for delivery to the lineprinter daemon, out-bound mail is spooled for delivery to remote systems, and UUCP files are spooled for transmission to UUCP neighbors. In-bound mail and news are spooled here for delivery to users, and at and cron jobs are spooled for delayed execution by the cron daemon.

      Screenshot

      • pwd : print working directory
      • ls : list directory
      • cd : change directory
      • cd / : take you to the root directory
      • cd ~ : take you to the user home directory
      • cd ./another_folder : navigate from current directory to another_folder
      • cd .. : navigate from current directory to parent directory
      • cd — : go back to the previous working directory
        • cd / : going to the root directory
        • cd ~/ : going to the home directory
        • cd — : going back to the root directory

        Screenshot

        • Every file in the system has an inode (Index node)
          • Contains all file information except the file content and name
          • A database of a file
          • They contain:
            • Inode number
            • File size
            • Owner information
            • Permission
            • File type
            • Number of links
              • Soft Link
              • Hard Link
              • A soft link is the same as a shortcut in Windows
              • Aka Symbolic link
              • It is a pointer to the original file
              • It is a file pointing to another file
                • Different inode number

                Screenshot

                • Different name of the same file
                • Same file size
                • Same inode number
                • You cannot differentiate between a real file and a hard link
                • They are kind of a copy of the file
                • If I change a hard link file content, it will reflect on the other files (the original and other hard links)
                • In case I delete the original file, the hard link file will still work
                • Be careful: You should not create hard links for directories. Normally they are not even allowed because they break the file system structure.

                Screenshot

                • ls : List files by alphabetic order
                • ls -i : This will list the index node number of each file
                • ls -a : This will show all the files (-a == all files) in your current directory, including hidden files
                • ls -l : Long listing of all files in the directory and some important information.
                • ls -t : Sort files by modification date
                • ls -r : List the files in reverse fashion (in this case reverse based on alphabetic order)
                • ls -rt OR ls -r -t : List the file in reverse fashion (in this case reverse based on modification date)
                • ls -li : Long listing + show inode ids
                • ls -lia : Long listing + show inode ids + hidden files
                • ls -R : Show current directory content plus any children/sub directory content as well
                • ls -Ra : Show current directory content plus any children/sub directory content as well + including hidden files

                Touch Command (Create a file)

                • Touch is used to create empty files
                  • touch file_name : Create a file called file_name
                  • touch file_name1 file_name2 file_name3 : Creates 3 files
                  • touch ‘my file’ or touch «my file» or touch my\ \ file : create a file with a name containing spaces
                    • \ is a scape sequence
                    • touch newFile
                    • echo «test» > newFile
                    • touch newFile : this will update the file timestamp and keep the content

                    Screenshot

                    MKDIR (Make directory) and RMDIR (Remove directory) Commands

                    mkdir directory_name mkdir directory_name1 directory_name2 directory_name3 
                    mkdir empty_dir rmdir empty_dir 
                    • In case you do rmdir in one directory that has files and another that is empty, it will only delete the empty one.
                    touch fileToDelete rm fileToDelete mkdir folder cd folder touch file cd .. 
                    • rm -R folder or rm -r folder
                    • In case of non-empty-directory you need to run rm with the recursive flag -R . Otherwise it will fail
                    • Also, the -R flag can be lowercase since it is not case sensitive for rm (although it is case sensitive for ls )
                    • rm -i : Prompt you before removing any existing file. the -i means interactive mode
                    • rm -f : Never prompt you before removing a file. And will not display a warning if the file you are trying to delete does not exist, meaning that it will ignore non existent files. -f means force
                    • rm -v : Verbose mode. It will print the name of each file before removing it.
                    • rm -R or rm -r : Recursively delete files. If the file is a directory, remove the entire directory and all its contents, including subdirectories.
                    • The cp command copies files or directories. It can be used in two different ways:
                      • Copy a file: cp file file2
                      • Make a copy of a directory: cp -R dir dir2 : dir2 does not need to exist
                        • This will make a copy of dir1 named dir2 (Assuming that dir2 didn’t exist)
                        • cp -i : Before overwriting an existing file, prompt the user for confirmation. cp will silently overwrite files by default.
                        • cp -v : Verbose mode (print the name of each file that was copied).
                        • cp -R : Recursively copy directories and their content. Just like the rm command, this option must be specified when copying a directory.
                        • cp -r : Same as cp -R
                        • The mv command can be used in two different ways.
Оцените статью
Adblock
detector