Linux Cheat-Sheet

Logged In User Details:

  1. whoami (Shows the username of the logged in user)

Directory Operations:

  1. pwd (Gives Present Working Directory)
  2. cd /dir (Navigate to 'dir' directory)
  3. mkdir dev (Make 'dev' directory)
  4. cd .. (Go to parent directory of the current directory)
  5. cd / (Go to root directory)
  6. cd ~ (Go to home directory)

File Listing Operations:

  1. ls (To list the files in the current directory)
  2. ls -a (To list all the files including hidden files)
  3. ls -l (To list the files with permissions)
  4. ls -t (To sort the list of files by last modified)
  5. ls -S (To sort the list of files by size)
  6. ls -R (To show the recursive list)
  7. ls -1 (One file per line)
  8. ls -r (To list the files in reverse order)

File Permission Numbers:

  • 4 (Read)
  • 2 (Write)
  • 1 (Execute)

File Permission Operations:

  1. chmod 777 filename (Change mode of file to 777)
  2. chmod -R 666 foldername (Change mode of folder to 666 recursively i.e including its subfolders as well)
  3. chown (Used to change the file owner or the group)
  4. chown new_owner_name filename (Owner of filename will be changed to new_owner_name)
  5. chown :dev file1.txt (group owner of file1.txt will be changed to dev)
  6. chown master:dev file.txt (group owner as well as the owner of file1.txt will be changed to master:dev)

Different ways to switch to the root user:

  1. sudo -i
  2. sudo -s
  3. su -i
  4. su -

How to change a password:

  • passwd username

How to add a new user:

  • useradd username

How to see the details of user like uid and the groups to which he belongs

  • id username

How to remove a user:

  • userdel username
  • userdel -r username (Deletes the user along with its home directory)