Advisory: Sophos Endpoint "Your connection isn't private" after reboot. Policy settings can be returned to normal. See: KB-000045954 for the latest updates.

Linux Command Reference Guide

The purpose of this article is to provide a quick reference list to go over some of the basic commands that you might use when working on a Linux device. It's strongly suggested to use man pages where further syntax or usage information is necessary. 

Command

Description

man

Displays the manual page for the given command. Requires a singular command as an argument
eg: man df

pwd

The ‘pwd’ command tells you the path of the ‘present working directory’ that you’re in. The command will return an absolute path, which is a path that always begins at the start of the drive.
eg: pwd (returns “/home/username/” if this is the directory you’re currently in)

cd

Change directories and navigate through the Linux filesystem. It requires either an absolute path or a sub-directory.
eg: "cd Photos" (Change directory to the sub-directory "Photos")
      "cd /home/username/Documents" (Change directory using an absolute path)

cd ..  (Change directory to the parent directory)
cd -   (Change directory  to the previous directory you were in)

ls

List the contents of the current directory. An absolute path can also be used to list the contents within the desired directory.
eg: "ls" or "ls /home/username/Desktop"

ls -l   (Display in a long listing format including permissions, hard links, file/directory ownership, group ownership, size, last modified date, and filename)
ll       (Is understood as "ls-l" by the os)
ls -a  (Displays hidden files/folders beginning with ".")
ls -h  (Makes filesize human readable by displaying K for kilobyte, M for megabyte, and G for gigabyte)

cat

Concatenate files and print on the standard output. This command will join strings together from the given file(s) and print them to the terminal. This command is commonly used to quickly read the content of text files or to copy the contents of a text file to another location/file. 
eg: "cat file1.txt

cat file1.txt > file2.txt (Will take the output from file1.txt and write to file2.txt)

cp

Copy files or directories. Requires you to specify the source file and the destination.
eg: "cp file1.txt /home/username/Desktop

cp -i (Prompts before overwriting files in the destination directory)
cp -f (If a file with the same name exists in the destination directory, remove it and try again)
cp -r (Copies recursively. When used with a directory, this will include all contents and sub-directories)

mv

Move or rename a file. Requires you to specify the source file and destination (or new name) to which you wish to move the file.
eg: "mv file1.txt newfile.txt" (Renames the file in the current directory)
      "mv file1.txt /home/username/Desktop/" (Moves the file to the destination directory)
      "mv file1.txt /home/username/Desktop/newfile.txt" (Moves the file to the destination directory and renames the file)

mkdir

Make a directory. Requires you to specify the name of the directory you wish to create.
eg: "mkdir NewDirectory" (Creates a new directory in the current location)
      "mkdir /home/username/Desktop/NewDirectory" (Creates a directory at the location specified using an absolute path)

rm

Remove files or directories. Requires you to specify the file you wish to remove.
eg: "rm newfile.txt" (Removes the file newfile.txt in the present working directory)

rm -i (Prompt before removing files)
rm -f (Force removal, ignores nonexistent files, and does not prompt prior to removing files)
rm -r (Can be a powerful/dangerous command to use, especially when used with the -f switch, and can be used to forcefully delete a directory which contains files within it) 

touch

Used to update file timestamps. The touch command can also be used to create an empty file. Multiple files can be created using one command.
eg: "touch file1" (Creates an empty file by the name of "file1". If the file already exists, the last access and modification timestamps are updated instead)
      "touch file1 file2 file3" (Creates 3 empty files. If the files already exist, the last access and modification timestamps are updated instead)

tar

An archiving utility. Used to create or extract archive files. Requires you to specify the destination archive file, as well as files/directories you wish to add to the archive.
eg: "tar -cf compressedfile.tar file1 file2 Logs/ " (Create an archive file by the name of "compressedfile.tar" containing file1, file2, and the directory "Logs/" including its contents)

tar -cf (The c switch is used to create an archive file, the f switch must be specified to define the name of the archive you wish to create)
tar -xf (The x switch is used to extract the contents of a .tar file, the f switch must be specified to define the name of the archive you wish to extract)
tar -cvf (The v switch enables verbose output)
tar -cfz
 (The z switch indicates for gzip compression to be used)

chmod

Change file/directory permissions. The chmod command is typically used along with numbers corresponding to user, group, and others' permissions, though letters can also be used. The +/- symbols along with r,w and x can be used.
eg: chmod a+r /PublicShare (Adds the read permission for all users)
      chmod go-r /PublicShare (Removes the read permission from group and user owners)
      chmod 755 /PublicShare (Allows full access for owners, read and execute permissions to group members and other users)

Number

Permission Type

Symbol

0

 No Permissions

---

1

Execute

--x

2

Write

-w-

3

Execute + Write

-wx

4

Read

r--

5

Read + Execute

r-x

6

Read + Write

rw-

7

Read + Write + Execute

rwx

wget

A command-line utility used to download files from the internet. 
eg:wget dzr-api-amzn-us-west-2-fa88.api-upe.p.hmr.sophos.com/.../SophosSetup.exe

wget -q (Downloads silently and suppresses output messages)
wget -r (Downloads files recursively following links to sub-folders)
wget -P (Allows you to specify the path where files will reside)

curl

Used to transfer data to/from a server using URLs. Can be used to download files, make HTTP requests, and API calls.
eg: curl dzr-api-amzn-us-west-2-fa88.api-upe.p.hmr.sophos.com/.../SophosSetup.exe

curl -f (Uploads a file)
curl -l (Follows any redirects and displays the final response)

uname

Displays information about the operating system and kernel.

uname -a (Prints all system information) 

ps

Displays information about running processes. If run with no arguments you will only see processes run in the current terminal session.

ps -e (Displays information about all processes (everyone). Some operating systems may use "a" in addition to "e")
ps -f (Displays more detailed information in a full format)
ps -u (Displays CPU and memory usage of each process in the output)
ps -x (Displays information on processes not associated with a terminal session, which may be started by the system or other users)

top

Shows real-time usage of system resources, similar to that of Task Manager in Windows. 

Ctrl+C (Terminates the top command)

echo

Primarily used to print text or messages to the terminal. Can also be used to print text into files using “>”.
eg: echo "Hello, World!"

su

Switch to another user account, or root (the superuser) if run without any arguments.
eg: su OtherUser (Change user to "OtherUser", a prompt is shown to enter the password)

sudo

Run a command as the root user. Requires a command as an argument. User accounts permitted to use sudo to elevate their commands are defined in the file '/etc/sudoers'. If this is not done, you will see the error "<user> is not in the sudoers file. This incident will be reported"
eg: sudo rm /home/OtherUser/OldPasswords.txt

grep

A text-search utility. Used to search for patterns or regular expressions within text files. A search string and file or directory must be provided.
eg: grep "127.0.0.1" Connections.log (Searches for 127.0.0.1 in the file Connections.log)

grep -r (Recursively searches through directories and files)
grep -i (Makes the search case-insensitive so both upper and lower case matches are returned)
grep -v (Inverts the match, returning lines which do not contain the specified search term)
grep -n (Returns the line number on which the result is found)

find

A file search utility. Requires you to supply the starting-point of the search, as well as the search expression.
eg: find /home/ -type f somefile.txt

find <start> -type (Allows you to specify the type of file you wish to search for f=file d=directory)
find <start> -size (Allows you to specify the size of the file you are looking for eg:+10K, +10M, +10G.

ifconfig

Allows you to view and configure network interfaces. If run with no arguments, a summary of the active network interfaces is shown.

ifconfig -a (Displays all information related to network interfaces, similar to that of ipconfig /all on Windows)
ifconfig eth0 (Displays information on the specified interface)
ifconfig eth0 up/down (Enables or disables the network interface)

traceroute

Traces the route a packet takes to get from your local computer to a destination host or website.
eg: traceroute google.ca

traceroute  -i  (Use ICMP Echo requests (ping) instead of UDP packets.
tracerouite -p <port> (Allows you to specify a destination port number)

nslookup

A tool used to query DNS servers. Requires an IP address or URL as an argument.
eg: nslookup google.ca

tail

Displays the last 10 lines of a text file if run without any arguments.
eg: tail Logs.log

tail  -f Logs.log (The "Follow" switch waits for data to be appended to the log-file and writes the lines to the terminal)
tail -n 20 Logs.log (Displays the last 20 lines from the specified text file)

head

Displays the first 10 lines of a text file if run without any arguments. 
eg: head Logs.log

head -n 20 Logs.log (Displays the first 20 lines of a text file)

diff

Compares two text files line by line and displays the differences between them. Requires you to specify the two files to compare.
eg: diff File1 File2

diff -q (Provides a brief output stating whether the files match or not, but does not provide further details on differences)
diff -w (Ignores all white-space in the files)
diff -r (Recursively compare directories and contents)
diff -s (Suppresses common lines and only displays the differing lines)

df

Displays disk space usage information. Displays information on all mounted filesystems if run without any arguments.

df -h (Displays disk space in human-readable format)
df -a (Display all filesystems including inaccessible ones)
df -l (Limit to local filesystem)



Formatting
[edited by: Qoosh at 12:24 AM (GMT -7) on 4 Oct 2023]