avatarShimon Brathwaite

Summary

The provided web content serves as a comprehensive Linux commands cheat sheet, covering basic and advanced commands for navigating and managing the Linux operating system.

Abstract

The web content is an extensive guide designed to assist users in understanding and utilizing Linux commands effectively. It includes essential shell commands such as ls, cat, pwd, cd, mkdir, whoami, id, rm, mv, cp, and also delves into file system commands like find, permissions-based commands such as chmod, chown, sudo, and chgrp, system process commands like ps, kill, jobs, bg, fg, and networking commands such as ip, ifconfig, ping, netstat, along with file processing commands including nano, echo, head, tail, grep, wc, sort, cut, and the use of the pipe command |. The guide is tailored for a wide range of users, from programmers to cybersecurity professionals, emphasizing the importance of Linux knowledge in the tech industry. Additionally, the author offers their services as a freelance writer for similar content creation and invites readers to follow for more articles.

Opinions

  • The author believes that understanding Linux commands is beneficial for individuals in various tech jobs, including programmers and cybersecurity professionals.
  • The guide is crafted with the intention of being an "all-in-one" resource, implying its value as a standalone reference for Linux users.
  • The inclusion of case-insensitive examples for commands like find suggests the author's consideration for common user needs and potential areas of confusion.
  • By providing examples of how to use the chmod command, the author conveys the importance of understanding file permissions and how they can be modified.
  • The author's note on the ss command as a modern replacement for netstat indicates an awareness of evolving Linux tools and a commitment to keeping the guide up-to-date.
  • The invitation to hire the author for content creation and the encouragement to follow for more content reflects the author's confidence in their expertise and the quality of their work.

Linux Commands Cheat sheet

Learn all of the basic and advanced linux commands

Image by OpenClipart-Vectors from Pixabay

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 directory
Ls -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 directory

4) cd: This allows you to change your directory

Commands and flags

cd [directoryname/]: This will change to a specific subdirectory
cd :With no additional arguments it will take you to the home directory

5) mkdir: This command allows you to create a new directory

mkdir [directoryname]: This will create a new directory in your current directory

7) whoami: This command displays your username

whoami: Use this command with no flags to display your current username

8) 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 desireddirectory
mv file.txt renamedfile.txt :This will rename the file

11) 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 lowercase
find /home -name “*.TXT” :searches all files with a .txt extension uppercase
find /home -iname “*.TXT” :Searches all files with a .txt extension case insensitive
find /home /tmp -iname “*.TXT:Searches all files with a .txt extension in /home and /tmp case insensitive
find -ls /home -iname “*.TXT” :Searches all files with a .txt extension case insensitive and provides file information on each match
find /home -size 72c -iname “*.TXT” :Searches all files with a .txt extension case insensitive and provides file information on each match
find /home -iname “*.TXT” -exec cat {} \; :Allows you to read the contents of all files that match your search

Permissions 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 filename

5. 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 information
ps -f :displays extra information including command line arguments
ps -fw :displays extra information but truncated
ps-fww :displays all information without truncation
ps -fww -e :displays all information for the current session and past sessions

8. 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 processes
Kill -9 <PID> :This forces the process to close

9. Jobs: This shows the status of processes in your current terminal

Jobs

10. Bg: You can use this to resume a process in your background

bg

11. Fg: This returns a background process to the foreground

fg

11. &: 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 information
ip addr show dev [interface name] :Shows information regarding a specific interface

13. Ifconfig: Shows IP address and network interface information for your machine

ifconfig

14. 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 want

15. 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 sockets
Netstat -nat :Adding the -t flag limits it to TCP connections
Netstat -nau :Adding the -u flag limits it to UDP connections
Netstat -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 nano
CTRL + X :exits the text editor

17. Echo: You can use this to redirect a message to a file of your choice

Echo “This is my message” > filename

18. 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 10

19. 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 10

20 .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 match
grep -i [string] [filename] :This performs a case insensitive search

21. Wc: This stands for word count and returns the number of lines, words and characters in a file.

wc filename.txt

22. Sort: This sorts a file’s contents in alphabetical order

Sort filename.txt
Sort -u filename.txt :Returns only unique lines in the output

23. 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 section

24. 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 values

Hire 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!

Technology
Coding Tutorials
Technology Hits
Illumination
Programming
Recommended from ReadMedium