Swapna Kumar Panda
Swapna Kumar Panda

@swapnakpanda

25 Tweets 3 reads Sep 22, 2022
60+ Useful Linux Commands for Everyone
➊ mkdir
⬘ It stands for "make directory".
⬙ It creates a directory inside the current directory.
❯ mkdir reports/
# Creates a single directory
❯ mkdir -p reports/finance/yearly/
# Creates entire directory structure
➋ cd
⬘ It stands for "change directory".
⬙ It changes the working directory to the specified one.
❯ cd icons
# Switch to the "icons" directory
❯ cd -
# Switch to the previous directory
❯ cd ..
# Switch to the parent directory
❯ cd
# Switch to the home directory
➌ pwd
⬘ It stands for "print working directory".
⬙ It outputs the absolute path of the directory you are in.
❯ pwd
/home/swapnakpanda/
➍ ls
⬘ It lists all files and, directories.
❯ ls
# For current working directory
❯ ls /home/
# For /home/
❯ ls -a
# Includes hidden files
❯ ls -R
# Recursively for subdirectories
❯ ls -l
# Lists in detail
❯ ls -ltr
# Sorted. Latest modified entry at the top.
➎ cp
⬘ It stands for "copy"
⬙ It copies a file or, directory to another place.
❯ cp file1.txt file2.txt
# Copies the file file1.txt to file2.txt
❯ cp -r dir1/ dir2/
# Copies entire directory "dir1" to "dir2"
➏ mv
⬘ It stands for "move".
⬗ It moves files and, directories to another directory.
⬙ It can be used to rename a file/directory.
❯ mv file1.js images/
# Moves the file
❯ mv file1.js file2.js
# Renames the file
➐ touch
⬘ It's used to create a new empty file.
⬙ It can also be used to change the modification date of a file to current time.
❯ touch new_file
# Creates a new empty file "new_file"
❯ touch -m old_file
# Changes the modification time
➑ cat
⬘ It stands for "concatenate".
⬙ It is used to view, create and concatenate files.
❯ cat file.txt
# Lists the contents of file1.txt to standard output
❯ cat > file.txt
# Creates a new file
❯ cat file1 file2 > file3
# Concatenates file1 & file2 to file3
➒ rm
⬘ It stands for "remove".
⬙ It's used to remove files and, directories.
❯ rm file1.txt
# Removes a file
❯ rm -r dir1
# Removes an empty directory
❯ rm -rf dir2
# Removes any directory
➓ find
⬘ It's used to search for files in a directory hierarchy based on a regular expression.
❯ find ./ -name "files.jpg"
# Searches for anything whose name is "files.jpg"
❯ find ./ -type f -name "*.java"
# Searches for files whose name ends with ".java"
➊➊ grep
⬘ Grep stands for Global Regular Expression Print.
⬙ It searches for a line in a file that matches a regular expression.
❯ grep "hello" message.txt
# Lists all lines that contain "hello"
❯ grep -c "hi" message.txt
# Displays the # of lines that contain "hi"
➊➋ head
⬘ It outputs the first few lines of a file.
❯ head message.txt
# Outputs first 10 lines
❯ head -n 5 message.txt
# Outputs first 5 lines
➊➌ tail
⬘ It outputs the last few lines of a file.
❯ tail message.txt
# Outputs last 10 lines
❯ tail -n 5 message.txt
# Outputs last 5 lines
❯ tail -f app.log
# Shows new entries in app.log
# as and when they get added
➊➍ diff
⬘ It is used to compare the contents of two files line by line.
❯ diff /dir1/package.json /dir2/package.json
# Lists out all differences
➊➎ alias
⬘ It allows you to define temporary aliases for the current session.
⬙ Aliases allow you to execute one or, more commands.
❯ alias lsa="ls -a"
# Creates a new alias "lsa"
❯ alias
# Lists all aliases for the current session
➊➏ chmod
⬘ It lets you change the mode (permission) of a file.
⬙ The basic permissions a file can have are
➥ r (read)
➥ w (write)
➥ x (execute)
❯ chmod +x "trunc.s"
# Makes the file "trunc.s" executable
➊➐ sudo
⬘ It stands for "superuser do".
⬙ It allows you to act as a superuser or, a root user while you are running a specific command.
❯ sudo apt-get update
➊➑ tar
❯ tar -cvf abc.tar *.c
# Creates a tar file (abc.tar) using all files with extension .c
❯ tar -xvf abc.tar
# Extract files from abc.tar
❯ tar -cvzf abc.tar.gz *.c
# Creates a tar file using gzip
❯ tar -xvzf abc.tar.gz
# Extract files from a gzip tar file
➊➒ echo
It displays the given text in the terminal
20. which
Shows the directory where the command is present
➋➊ whoami
Displays the username who currently is using this session
➋➋ man
Displays the manual page of any command
➋➌ chown
To change the ownership
➋➍ du
To check how much space a file or a directory takes
➋➎ ps
Lists the processes that the current shell session is running
➋➏ kill
To kill (terminate) a process
➋➐ free
Show the amount of free memory
➋➑ vmstat 10
Every 10 seconds, show statistics
➋➒ iotop
Displays the disk IO usage details
30. systemctl
Manage systemd and services
➌➊ journalctl
To view systemd, kernel and journal logs
➌➋ env
Prints list of environment variables
➌➌ host
Used for DNS lookup operations
➌➍ hostname
Used to obtain the DNS name
➌➎ ping
Checks the network connectivity b/w host and server
➌➏ curl
To transfer data to or from a server
➌➐ wget
To retrieve/download content from the internet
➌➑ history
Displays the commands you used in the past.
➌➒ clear
Clear the terminal window
40. exit
It ends a shell session and, closes the terminal you are using.
Hey 👋
I am a Tech Writer, Educator, and Mentor from India 🇮🇳, here sharing
✰ Tutorials
✰ Tricks
✰ Career Tips
✰ Cheat Sheets
✰ Practice Questions
✰ Project Ideas
on
➠ Web Development
➠ Data Structures and Algorithms
➠ Databases
Thanks for reading. 🙏

Loading suggestions...