100 Basic Linux Commands 📇

  1. Execute the previous command used:
    !!

  2. Execute a previous command starting with a specific letter. Example:
    !s

  3. Short way to copy or backup a file before you edit it. For example, copy nginx.conf
    cp nginx.conf{,.bak}

  4. Toggle between current directory and last directory
    cd -

  5. Move to parent (higher level) directory. Note the space!
    cd ..

  6. Go to home directory
    cd ~

  7. Go to home directory
    cd $HOME

  8. Go to home directory (when used alone)
    cd

  9. Set permissions to 755. Corresponds to these permissions: (-rwx-r-x-r-x), arranged in this sequence: (owner-group-other)
    chmod 755 <filename>

  10. Add execute permission to all users.
    chmod a+x <filename>

  11. Changes ownership of a file or directory to .
    chown <username>

  12. Make a backup copy of a file (named file.backup)
    cp <file> <file>.backup

  13. Copy file1, use it to create file2
    cp <file1> <file2>

  14. Copy directory1 and all its contents (recursively) into directory2
    cp -r <directory1> <directory2>/

  15. Display date
    date

  16. Zero the sdb drive. You may want to use GParted to format the drive afterward. (Requires sudo).
    dd if=/dev/zero of=/dev/sdb

  17. Display disk space usage
    df -h

  18. Take detailed messages from OS and input to text file
    dmesg>dmesg.txt

  19. Display a LOT of system information. I usually pipe output to less. You need elevated permissions to run this (sudo).
    dmidecode

  20. Display BIOS information. You need elevated permissions to run this (sudo).
    dmidecode -t 0

  21. Display CPU information. You need elevated permissions to run this (sudo).
    dmidecode -t 4

  22. Search for installed packages related to Apache
    dpkg –get-selections | grep apache

  23. Shows you where in the filesystem the package components were installed
    dpkg -L <package_name>

  24. Display detailed disk use for each subdirectory
    du / -bh | less

  25. Print the environment variable PATH
    echo $PATH

  26. Display environment variables like USER, LANG, SHELL, PATH, TERM, etc.
    env

  27. Opens a picture with the Eye of Gnome Image Viewer
    eog <picture_name>

  28. Quit the terminal (or give up super-powers if you’ve previously done sudo su)
    exit

  29. Display memory usage
    free

  30. Easy way to view all the system logs.
    gnome-system-log

  31. Search through file(s) and display lines containing matching string
    grep <string> <filename>

  32. Get the number of seconds since the OS was started
    grep btime /proc/stat | grep -Eo "[[:digit:]]+"

  33. Display the last 1000 commands
    history | less

  34. Display the name of the local host
    hostname

  35. Display time.
    hwclock –show

  36. Display user id (uid) and group id (gid)
    id

  37. Display your local IP address and netmask
    ifconfig

  38. Wireless network interface
    iwconfig

  39. Display wireless network information
    iwlist

  40. Kill process by name. You need elevated permissions to run this (sudo).
    killall process

  41. Get the date and time of the last system shutdown
    last -x | grep shutdown | head -1 | grep -Eo "[A-Z][a-z]{2} [[:digit:] ][[:digit:]][[:digit:]]{2}:[[:digit:]]{2}"

  42. Quit shell session (only for a shell you’ve logged into like one of the virtual consoles)
    logout

  43. List non-hidden files and subfolders in current directory (like dir for windows). Use -R for recursive and -a to include hidden files.
    ls

  44. Display file access permissions for all files in the current directory. The format for permissions is drwxrwxrwx where the order is owner-group-other and the numeric values are read=4, write=2, execute=1.
    ls -l <filename>

  45. List all available applications, in case you’ve forgotten how to open Open Office Writer or another application from the terminal (oowriter)
    ls /usr/bin | less

  46. Display more networking information
    lshw -C network

  47. Display kernel modules currently loaded
    lsmod

  48. Display sound, video, and networking hardware
    lspci -nv | less

  49. Display usb-connected hardware
    lsusb

  50. Read the command’s man page (manual)
    man <command>

  51. Create new directory at specified location
    mkdir <dirname>

  52. Move file to specified directory
    mv <file> <dir>

  53. Rename file1 to file2
    mv <file1> <file2>

  54. Display routing table
    netstat -rn

  55. Print environmental variables
    printenv

  56. List the processes currently running by this user. There are many useful options, view them with ps –help
    ps -Af

  57. Print working directory
    pwd

  58. Delete file
    rm <filename>

  59. Delete directory and all it’s contents
    rm -rf <dir>

  60. Removes all files that end in txt in current directory
    rm *.txt

  61. Delete directory (will only work if it’s empty)
    rmdir <dir>

  62. Display your default gateway listed under “default”
    route

  63. Completely destroy all traces of the file. This takes a while. -n 7 means seven overwrites, -z means zero the bits afterward to hide shredding, -u means delete the file when done, and -v means verbose.
    shred -zuv -n 7 <file>

  64. Shutdown now.
    shutdown -h now

  65. Restart now.
    shutdown -r now

  66. Log into remote computer
    ssh <IP address>

  67. Open the root shell, giving yourself superuser permissions until you relegate your powers with exit. Unlike sudo su which does the same thing, this method of starting the root shell is uncorrupted by a user’s environmental variables.
    sudo -i

  68. Open the root shell, like sudo -i, but this method retains the user’s environmental variables. Relegate superuser permissions and return to normal shell with exit.
    sudo su

  69. Creates a compressed archive of the specified directory and all files/directories under it.
    tar czf <dirname>.tgz <dirname>

  70. Expand the contents of a compressed archive and extract to current directory.
    tar zxvf <archive>

  71. List current processes by cpu use. This is very useful. Press q to quit and h for help.
    top

  72. Create an empty file if it doesn’t exist
    touch <filename>

  73. Display the name of the current terminal
    tty

  74. Display your linux kernel
    uname -a

  75. Display your machine’s processor architecture
    uname -m

  76. Returns one-line synopsis from the command’s man page
    whatis <command>

  77. Returns the location of the program in the filesystem
    whereis <command>

  78. Returns the application’s path
    which <command>

  79. Display the users logged into the machine
    who

  80. Display your login name
    whoami

  81. This will display the output of test.log as it is being written to by another program
    tail –follow test.log

  82. If you’ve just navigated to a directory shell and want to open a file or application IN that directory. Just use this command followed by the filename
    ./filename.txt

  83. Escape operator. Use it before a space if you’re trying to open a file that has whitespace in the name.
    \

  84. The tilde represents your home directory.
    ~

  85. Run any command when the system load is low
    batch <command>

  86. Display cpu info
    cat /proc/cpuinfo

  87. Display memory usage
    cat /proc/meminfo

  88. Display networking devices
    cat /proc/net/dev

  89. Display performance information
    cat /proc/uptime

  90. Display kernel version
    cat /proc/version

  91. Display file contents
    cat <filename>

  92. List partition tables
    fdisk -l

  93. Show the properties/compression of a file or package
    file <package_name>

  94. Find a file. Search Linux filesystem for a file name.
    find / -name <filename>

  95. To create a *.gz compressed file
    gzip test.txt

  96. To uncompress a *.gz file
    gzip -d test.txt.gz

  97. Display compression ratio of the compressed file using gzip -l
    gzip -l *.gz

  98. Output file status
    stat filename.txt

  99. Download a file from the internet
    wget http://remote_file_url

  100. Show list of last 10 logged in users.
    last -n 10

  101. Display a tree of processes
    pstree