Linux Commands Cheat sheet
Learn all of the basic and advanced linux commands

Linux is an operating system like Windows, IOS, and MAC OS. Linux is one of the most popular platforms on the planet, for example, android is powered by the Linux operating system. Whether you’re a programmer, a cybersecurity professional, or any other job in tech it’s useful to understand the Linux shell commands. This guide is an all-in-one cheat sheet of the most important Linux commands you need to know for navigating the Linux OS.
Basic Linux Shell Commands
1) LS: Lists all files in the current directory. Commands and flags
ls: List’s all regular files in the current directoryLs -a: Lists all hidden and non hidden files in the current directory (hidden files begin with a .)2) Cat: Reads the contents of a file
Commands and flags
Cat [file.txt] : This will output the contents of the file that you use it on.3) pwd: This tells your what the full path for your current work directory is
Commands and flags
pwd : This will display the full path for your current directory4) cd: This allows you to change your directory
Commands and flags
cd [directoryname/]: This will change to a specific subdirectorycd :With no additional arguments it will take you to the home directory5) mkdir: This command allows you to create a new directory
mkdir [directoryname]: This will create a new directory in your current directory7) whoami: This command displays your username
whoami: Use this command with no flags to display your current username8) id: This command displays your user name, user ID and group information
id 9) rm: This command deletes files
rm [filename.txt]10) mv: This can be used to move files or rename files
mv file.txt [desireddirectory/] :This will move the file to a desireddirectorymv file.txt renamedfile.txt :This will rename the file11) cp: Copy a file from location to another
cp [filename/filepath] [desired filename/filepath]File System Commands
1) Find: This allows you to scan a directory for a specific file(s)
find /home -name “*.txt” :searches all files with a .txt extension lowercasefind /home -name “*.TXT” :searches all files with a .txt extension uppercasefind /home -iname “*.TXT” :Searches all files with a .txt extension case insensitivefind /home /tmp -iname “*.TXT” :Searches all files with a .txt extension in /home and /tmp case insensitivefind -ls /home -iname “*.TXT” :Searches all files with a .txt extension case insensitive and provides file information on each matchfind /home -size 72c -iname “*.TXT” :Searches all files with a .txt extension case insensitive and provides file information on each matchfind /home -iname “*.TXT” -exec cat {} \; :Allows you to read the contents of all files that match your searchPermissions Based Commands
1) Ls -l: Identify the owner and the permissions associated with a file
Ls -l [filename] 2) Chmod (short for change mode): Allows you to change the permissions of a file for users, group and others in that order.
The permissions are based on numerical values: 4= read 2= write 1=execute.
Example #1 read access For example if you wanted to give the user(owner) of a file read access and block access to everyone else you would run: chmod 400 filename. If you want to give everyone read access you run chmod 444 filename. Example #2 read and write access If you want to give the user(owner) read and write access and block access to everyone else you would run: chmod 600 filename. If you wanted to give read and write access to everyone you would run chmod 666 filename.
Example #3 changing to SETUID Whenever you run chmod there is an assumed 0 in front of the command. Therefore Chmod 700 = chmod 0700, this means that the file is executed with the privileges of the user that is running it. To run a file with the privileges of the owner you must set it to 4 (SETUID). So you would run chmod 4700 to make it SETUID.
Chmod 600 filename :This gives the owner full read and write access, no one else can access the file.Chmod 700 filename :This gives the owner full read, write and execute access but no one else can access the file.3. Ls- ld: Identify the owner and permissions of a directory
ls -ld [directoryname]4. Chown (short for change ownership): This command allows you to change the ownership of a file on the system
Command: chown username filename5. Sudo (short for super user do): This attempts to run a command as a privileged user.
Below is an example of using sudo to run the chown command from above but it can be used with any command
Sudo chown [username] [filename]6. Chgrp (short for change group): This will change the group assignment of a file
chgrp [groupname] [filename]System Process Commands
7. Ps: This command lists your running processes information
ps :displays just process informationps -f :displays extra information including command line argumentsps -fw :displays extra information but truncatedps-fww :displays all information without truncationps -fww -e :displays all information for the current session and past sessions8. Kill: To terminate a process you can use the kill command
Kill <PID> :It attempts to terminate the process but this signal can be ignored by some processesKill -9 <PID> :This forces the process to close9. Jobs: This shows the status of processes in your current terminal
Jobs10. Bg: You can use this to resume a process in your background
bg11. Fg: This returns a background process to the foreground
fg11. &: By adding this to the end of a command you can run a process in the background
[Processname] &Network Commands Linux
12. Ip: This tool is used for managing network interfaces.
ip addr show :Shows your machine’s network interface informationip addr show dev [interface name] :Show’s information regarding a specific interface13. Ifconfig: Shows IP address and network interface information for your machine
ifconfig14. Ping: A basic connectivity test where your machine sends data packets to another machine and awaits a response
ping [IP address]ping -c 4 [IP Address] :to limit the amount of packets you send to 4. Though it can be any number you want15. Netstat: This command line tool can be used to display inbound and outbound connections
Netstat -na :This shows all network connections inbound and outbound, including unix socketsNetstat -nat :Adding the -t flag limits it to TCP connectionsNetstat -nau :Adding the -u flag limits it to UDP connectionsNetstat -natp :Adding the -p flag shows PID and process name. Must be run as root so you may need to add sudo to the front of the command (sudo Netstat -natp)Special Note: A modern replacement for netstat is the ss command, but it accepts all of the same flags and produces the same results.
File Processing Commands
16. Nano: Linux default text editor
Nano [filename.txt] :opens the file in nanoCTRL + X :exits the text editor17. Echo: You can use this to redirect a message to a file of your choice
Echo “This is my message” > filename18. Head: This will retrieve the first 10 lines from any file you specify
Head [filename/path]Head -n 2 [filename/path] :to specify a number of lines other than 1019. Tail: This will retrieve the last 10 lines from any file you specify
Tail [filename/path]tail -n 2 [filename/path] :to specify a number of lines other than 1020 .Grep: This allows you to search for one or more lines in a file or stream of data
grep [string] [filename]grep -C2 [string] [filename] :Adds to lines of context, a line before and a line after the matchgrep -i [string] [filename] :This performs a case insensitive search21. Wc: This stands for word count and returns the number of lines, words and characters in a file.
wc filename.txt22. Sort: This sorts a file’s contents in alphabetical order
Sort filename.txtSort -u filename.txt :Returns only unique lines in the output23. Cut: This allows you to separate out specific parts of a text file.
You do this by choosing a delimiter (what the command will use to separate the file into sections) and then specifying which section you want (section 1,2,3 etc)
cut -d , -f 1 filename :This command tells the computer divided the text into sections by each “,” and then return the first section24. The pipe command | : This allows you to take output from one command and use it as input to another one.
cat filename.txt | sort -u :This would take the output from cat and sort it for unique valuesHire me to write for you!
I’m a freelance writer available for hire, if you would like me to create content like this for your website you can reach me at [email protected].
Follow for More Content!
If you enjoyed this article and would like to get more content please follow me and I’ll return the favor! Also, feel free to comment on this article, ask questions, leave statements, or give suggestions for any other articles you would like me to write!





