ls command
The ls command lists files and directories.
ls [options] [path]
ls / List root directory ls .. List parent directory ls ~ List home directory ls -a Include hidden files ls -d Only directories ls --color =always/never/auto ls -i List with index number ls -l List with long format ls -r Reverse order ls -R Recursively directory tree ls -s List file size ls -S Sort by file size ls -X Sort by extension name ls -la List with long format and hidden files ls -ls List with long format and readable file size ls -lh List with long format and file size ls -lt List with long format and order by datetime if you specify a path ls will returns path's content. if you dont specify ls will use current path.
pwd command
The pwd command prints working directory.
pwd [options]
pwd -L Prints the symbolic path pwd -P Prints the actual path cd command
The cd command changes working directory in the file system.
cd [directory]
cd Returns home directory cd .. Moves up directory cd - Goes back to the previous directory sudo command
The sudo command gives root permission for non-root users while running a command.
sudo [options] command
-b Executes in the background. -k Invalidates the user's timestamp. -p Allows you to customize the password prompt. -n Allows to execute command without password prompt. su command
The su command lets you switch to another user.
su username
whoami command
The whoami command lets you check current logged in user.
whoami
chmod command
The chmod command changes the permissions for files or directories.
chmod [options] [permission] file-or-directory
Permissions
r Read Permission w Write Permission x Execute permission + Add permission - Remove permission = Set the permissions to the specified values Options
-R Applies the changes as recursively. -v Displays a message for each item processed. -c Displays a message only changes items. chown command
The chown command changes the ownership of files or directories.
chown [options] new-owner:new-group file-or-directory
-c Displays a message when process is done. -v Enables verbose mode. useradd command
The useradd command creates a new user account.
useradd [options] new-user
-p Creates user with a password. -u Creates user with a specific user id (UID). -g Creates user with a specific group id (GID). -M Creates user without a home directory. -e Creates user with an expiry date. -c Creates user with a comment. passwd command
The userdel command sets or changes the password.
passwd new-password
userdel command
The userdel command removes user.
userdel user-name
df command
The df command checks system disk usage.
df [options] path
-a Displays pseudo, duplicate, and inaccessible file systems. -h Displays human readable format, uses 1024. -H Displays human readable format, uses 1000. -l Displays only local file systems. -T Displays file system type. du command
The du command checks sizes of directory and its content.
du [options] path
-a Displays with hidden files and directories. -h Displays human readable format. -S Displays only parent directories. top command
The top command displays all running process.
top [options]
htop command
The htop command displays all running process.
htop [options]
ps command
The ps command displays all running process.
ps [options]
kill command
The kill command terminates a process.
kill [signal] process-id
Signals
SIGHUP It hangup detected on controlling terminals or death of controlling process. SIGINT It interrupts from keyboard. SIGKILL It kills signal. SIGTERM It terminates signal. shutdown command
The shutdown command turn off linux system.
shutdown
ping command
The ping command tests the reachability of a remote server.
ping [options] remote-server
-V Displays ping utility version. -c Sends number of x packets. -s Sets packet size. -i Sets send interval. -w Sets timeout. wget command
The wget command downloads file from the internet via HTTP/HTTPS or FPT protpcols.
wget [options] url
-v Displays version. -h Displays available commands. -o Creates log file. -b Runs in the background. -i Reads urls from a file. curl command
The curl command sends or receive data.
curl [options] url
-# Displays process. --slient Slient mode. -X Defines HTTP method like GET, POST. -o Save downloaded data to the local. -u Sets username/password. uname command
The uname command displays OS information.
uname [options]
-a Displays all available information. -s Displays kernel name. -n Displays network name. hostname command
The hostname command displays hostname.
hostname [options]
-i Displays ip adress. -a Displays hostname alias. -A Displays fully qualified domain name (FQDN). time command
The time command displays given command's execution time.
time command
systemctl command
The systemctl command manages services on the system.
systemctl command service-name [options]
Commands
start Starts a service. stop Stops a service. restart Restarts a service. enable Enables a service. disable Disables a service. reload Reloads a service. status Displays service status. mkdir command
The mkdir command creates one or more directories in the file system.
mkdir [options] directory1 directory2
mkdir --help Displays help. mkdir --version Displays the version and additional information. mkdir --verbose Displays a message when process done. mkdir --p Ignores error message like 'directory already exist'. mkdir --m a=rwx Gives permission like chmod command. rmdir command
The rmdir command deletes empty directories in the file system.
rmdir [options] directory
rmdir -p directory Force delete non-empty folders. The rmdir command gives exception if the directory doesnt empty. That case you can use -p option.
rm command
The rm command deletes files from a directory.
rm [options] file1 file2
rm -r directory Removes a folder and it's contents recursively. rm -i directory Displays a confirmation message before remove. rm -f directory Deactivate the confirmation message. cp command
The cp command copy files from a directory to another directory.
cp /source-path/file /target-path/file
cp -R /source-path /target-path Copy source direstory to target directory with all content. mv command
The mv command move files from a directory to another directory.
mv /source-path/file /target-path/file
cat command
The cat command has a few usages.
cat file.txt
Printing content of the file.
cat > file.txt
Printing standart output into the file.
cat file1.txt file2.txt > target.txt
Concatenate the files into the single file.
grep command
The grep (Global Regular Expression Print) command using for searching text with a specific pattern in the text files.
grep [options] pattern file.txt
-c Displays how many count of the lines matched with specific pattern. -h Displays matched lines without filename. -i Ignores case insensitive. -l Displays list of filenames. -n Displays matched lines with line number. -v Displays not matched lines. -e Specifies expression. -f Takes patterns from a file. -w Match whole word. -o Displays only the matched parts of the line. sed command
The sed command using for searching and replacing patterns in the text files.
sed [options] 'command/current-pattern/new-pattern' file.txt
-i Updates the file without printing. -n Prints only updated lines. -e Allows multiple commands. -f Takes commands from a file. -r Enables regular expression. awk command
The awk command using for searching and replacing regular expression patterns in the text files.
awk '/regex patters/{action}' file.txt
sort command
The sort command rearrange a file's content in a specific order.
sort [options] file.txt
-o Specifies an output file for the rearranged data. -r Sorts Reverse order. -n Sorts by number. -c Checks file already sorted. -u Sorts and removed duplicated lines. -M Sorts by month names. cut command
The cut command displays specific section from a file.
cut [options] file.txt
-b Selects only the specified bytes in the list. -c Selects only the specified characters in the list. -d Sets delimiter. -f Selects only the specified fields in the list. diff command
The diff command displays differences from two files.
diff [options] file1.txt file2.txt
-c Differences in context mode. -u Differences in unified mode. -i or --ignore-case Ignores case insensitive comparison. -ignore-all-space Ignores white spaces. -brief Displays only files differ or not. -recursive Recursively compare directories. -y or --side-by-side Displays in a side-by-side. head command
The head command displays top x lines of the text files.
head [options] file.txt
-n Displays number of lines. -c Displays number of bytes. -q Displays multiple files without quit. -v Enables verbose mode. tee command
The tee command captures standart inputs and write it both standart output and file.
tee [options] file.txt
-a Appends the file. locate command
The locate command searches files and displays its path.
locate [options] search-keyword
-r Allows use regex for search keyword. -i Allows turn off case insensitive. find command
The find command searches files with a specific path.
find /path [options] expression
-name pattern Searches for specific name or pattern. -type type Searches for specified types like f for files and d for directories. -size [+/-]n Searches for size like +n finds larger files and -n smaller files. -exec command {} \; Executes specific command on each founded file. -empty Searches for empty file and folders. -delete Deletes files for matched. tail command
The tail command displays last x lines of the text files.
tail [options] file.txt
-n Displays number of lines. -c Displays number of bytes. -q Displays multiple files without quit. -v Enables verbose mode. -f Enables follow file changes. file command
The file command checks a file's type like txt, sh or other.
file file.txt
touch command
The touch command creates one or more empty files.
touch file.txt
touch -a file.txt Changes the access time. touch -c file.txt Deny to creation if it's not exist. touch -d file.txt Changes modified time. touch -m file.txt Changes the modified time. vim command
The vim command creates or edit text files.
vim file.txt
Opens given file name as edit mode if file exist. If file doesn't exists created an empty one. Vim has lot of command inside the editor like save changes (:w), quit edior (:q).
nano command
The nano command creates or edit text files.
nano file.txt
Nano is a text editor and it has specific command.
zip command
The zip command compresses one or multiple files and creates zip file.
zip [options] file.zip file.txt
zip -d file.zip file.txt Allows you to remove specific file from a zip file. zip -u file.zip file.txt Allows you to update specific file from a zip file. zip -m file.zip file.txt Allows you to move specific file from a zip file. zip -r directory.zip /directory Allows you to recursively zip a directory. zip -r file.zip -x file.txt Allows you to exclude specific files from being included in the zip archive. zip -v directory.zip /directory Enables verbose mode. unzip command
The unzip command extract a compressed zip file into a folder.
unzip file.zip
tar command
The tar command bundles multiple files or directories into an archive without compression or with gzip or bzip2 compression.
tar [options] file.tar file1.txt file2.txt
-c Creates an archive file from files or directories -x Extract files and directories from an exist archive. -f Specifies the filename of the archive. -t Displays files and directories from an archive. -u Adds new files or directories to an exist archive. -r Adds new files or directories to an exist archive without recreating the entire archive. -v Enables verbose mode. -A Concatenates two or more archive files into a archive. -z Uses gzip compression. -j Uses bzip2 compression. -W Verifies archive file if content is corrupted or not.
Common Linux Commands
Linux commands are instructions you type into a terminal or shell to interact with the Linux operating system. These commands allow users to perform a variety of tasks, from navigating the file system and managing files to configuring the system and running programs. Linux commands are part of the command-line interface (CLI) and are a fundamental way to control and administer Linux systems.