Linux_command cheat_sheet

Linux_command cheat_sheet

Below are some important commands you need to know to start your journey into Linux.

User-based command

  1. who — display which user is logged in

  2. whoami — display the system’s username

  3. id —display names and numeric ID’s (UID or group ID) of the current user.

  4. groups — display the groups to which the user is belonging to.

  5. adduser username — Adds a user

  6. Enable/Disable user — To disable / lock the password of user account use below command. This will not disallow ssh-access on Ubuntu. This prepends a ! to the password hash so that no password will match it anymore.

    • sudo passwd -l ‘username’ — Disable a user
    • sudo passwd -u ‘username’ — Enable a user

7.sudo userdel -r ‘username’ — Delete a user

8.sudo usermod -a -G GROUPNAME USERNAME — Add user a to a usergroup

9.sudo gpasswd — delete USERNAME GROUPNAME— Remove user from a user group

10.users — display the username of all users currently logged in

11.lastlog — display the details of a recent login of all users

12 . Five ways to become a sudo user in Linux OS

  • sudo -i
  • sudo -s
  • sudo su -
  • su root
  • su -

Directory based commands

  1. pwd — display present working Directory

  2. ls — to list directories (mkssoftware.com/docs/man1/ls.1.asp)

  3. mkdir — to create a directory

  4. rmdir — to remove the directory

  5. cd — to change directory to $HOME directory

  6. cd /folderpath — to change the directory to a particular path

  7. cd .. — change the directory to one level up in the directory tree

File-based commands

  1. touch filename — to create an empty file

  2. rm filename — remove a file

  3. rm -r directory — delete a directory recursively along with its content

  4. cp file1 file2 — copies the content of file1 into file2

  5. cp -r dir1 dir2 — copies the content of dir1 into dir2

  6. cat filename — print the content of the file

  7. head filename — print the first 10 lines of a file

  8. tail filename — print the last 10 lines of a file

System based commands

  1. uname -a — display system and kernel

  2. date — display system date

  3. uptime — display uptime

Hardware-based commands

  1. cat /proc/cpuinfo — display information about the CPU
  2. free — display total memory available and the memory used
  3. lsblk — list of disks and their partitions

Seach files

  1. find / -name "hosts" — Find files owned by hosts in / directory
  2. find / -name "hosts*" — Find files starting with hosts in / directory
  3. find / -user username— Find files owned by users
  4. find / -size +2G — Find file whose size is greater than 2GB

File Permissions

###File Permission numbers

4 — read(r), 2 — write(w), 1 — execute(x)

  1. chmod 755 filename — set read, write and execute permission to owner and read, execute permission to group and everyone
  2. chown username filename — change ownership of the file

Process commands

  1. ps — to check active running processes
  2. top — display real time processes
  3. kill pid — kill process with pid
  4. killall name — Kill all processes beginning with the name

Archive and Compression commands

  1. tar -cvf my_archive.tar /home — create archive file name my_archive of home directory
  2. tar -xvf my_archive .tar— extract my_archive.tar to current directory

Terminal shortcuts

  1. Tab — autocomplete commands
  2. Ctrl+C — kills currently executing the command
  3. Ctrl+L — clear terminal
  4. Ctrl+D — to get back to the original user
  5. Ctrl+U — erase everything from the current cursor position to the beginning
  6. Ctrl+A — Move the cursor to the beginning of the line
  7. Ctrl+E — move the cursor to the end of the line

Thank you for reading and I hope you found it useful. Follow me for more :)