Guest User!

You are not Sophos Staff.

Linux Command Cheat Sheet

The purpose of this recommended read is to go over some of the basic, as well as advanced commands that you might use when working on a Linux machine.

 

Command

Description

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. An example of an absolute path is /home/username.

 

cd

Change directories and navigate through the Linux filesystem. It requires either an absolute path or the name of 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 them to file2.txt)

 

cp

Copy files or directories. Requires you to specify the source file and destination to which you wish to copy the file.
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. Can be used to delete a directory which contains files within it) 

 

touch

Change 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 it's 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 all users)
      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

 

kill

 

 

kill

 

 

wget

 

 

curl

 

 

uname

 

 

ps

 

 

top

 

 

vi

 

 

echo

 

 

su

 

 

sudo

 

 

grep

 

 

find

 

 



pending
[edited by: Qoosh at 1:14 AM (GMT -7) on 30 Sep 2023]