Linux Command Cheatsheet For Beginners
In this tutorial you’ll learn basic and the most used Linux commands. This Linux Command Cheatsheet For Beginners will help you gain the necessary understanding of daily task execution through the terminal.
Linux (opens in a new tab) is the preferred Operating system among professional developers because it makes very efficient use of the system’s resources.
The commands discussed below may not help you become a pro in a day, but practicing all and learning new things along with implementing everything in a positive manner will make you an efficient Linux user.
1. File Management
Command | Description |
---|---|
ls | Lists all the files in the current directory |
ls -l | Shows files along with permissions |
ls -al | Shows a list of all the files including hidden files |
ls -lt | Sorting the listing by time modification |
pwd | Shows the Present Working Directory |
cd | Prints Current Directory |
cd .. | Change the directory to the parent directory |
cd – | Change to the previous directory |
cd dir_name | Change the directory to "dir_name" |
mkdir dir_name | Make a directory with "dir_name" |
cat > filename | Creates a new file with 'filename' |
cat filename | Displays file content |
cat file1 file2 > file3 | Concatenate or join two files into one |
touch filename | Create a new file with 'filename' |
rm filename | Removes the file |
rm -r dir | Removes a directory named 'dir' |
cp file1 file2 | Copy file1 and call it file2 |
cp -r dir1 dir2 | Copy contents of directory 'dir1' to 'dir2' |
mv file1 file2 | Move file1 to file2 |
echo 'Hi' > data.txt | Enter content into a file |
echo 'There!' >> data.txt | Append text to an existing file in Linux |
nano filename | Opens file in an editor |
vim filename | Enables an efficient text editor |
tar -cvf archived.tar /indgeek | Compress files and folders in Linux |
tar -xvf archived.tar | Extracts the tar archive file |
Command | Description |
---|---|
sudo | Allows regular users to run with Superuser privileges |
apt-get | Command used to install and update packages |
ps | Displays the current working processes |
man | Opens the help manual of a command |
pidof | Gives the Process ID (PID) of a process |
kill PID | Kill the process with the given PID |
top -u igeek | Display specific User process details |
nice | Starts a process with a given priority |
renice | Changes the priority of an already running process |
df | Gives free hard disk space on your system |
free | Gives free RAM on your system |
bg | To send a process to the background |
fg | To run a stopped process in the foreground |
Read More: Basic SQL Cheat Sheet
3. Permissions
Linux permissions grating is a tricky task that you may memorize with simple syntaxes.
Remember providing ‘Read Permission‘ to any user would only allow them to read the file, that specific user won’t be able to write/ modify or execute that file or application.
Users:
Every file and directory on a Linux system can be assigned 3 types of Owners,
- Owner: The Owner is the creator of a specific file or Directory
- Group: A Group can contain multiple users
- Others: A person who has neither created the file nor belongs to a user group who owns the file.
Character | Meaning |
---|---|
u | User/Owner |
g | Group |
o | Other |
a | All |
+ | Adds permission |
– | Removes permission |
= | Assigns the permission |
r | Read Permission |
w | Write Permission |
x | Executing permission |
0 | No permissions |
1 | -x (execute only) |
2 | -w- (write only) |
3 | -wx (write and execute) |
4 | r- (read only) |
5 | r-x (read and execute) |
6 | rw- (read and write) |
7 | rwx (read, write, and execute) |
Permissions Examples
chmod +rwx filename
: Adds all permissions to a user.chmod -rwx filename
: Removes all permissions from a user.chmod +w filename
: Allows users to modify the file.chmod +r-x filename
: Allows a user to read and execute.chmod 777
: Completely permits Owner, Groups, Others.
Changing Ownership
chown user
: Changes the ownership of a file/directory.
4. System
Command | Description |
---|---|
users | Shows the username of users currently logged in |
w | Displays who is online |
whoami | Displays the current logged-in user to this system |
finger user | Shows information about the user |
sudo adduser username | Adds a user with a username |
sudo userdel -r 'username' | Removes 'username' user |
sudo passwd -l 'username' | Changes the password of a user |
sudo usermod -a -G Gname Uname | Add user to a Group |
uname -a | Shows Kernel information |
uname -m | Shows Architecture information |
cat /proc/cpuinfo | Displays CPU information |
cat /proc/meminfo | Displays memory information |
free -t | Shows total memory used & available |
Notes:
- Use
sudo
before commands that require administrative privileges. - For
sudo userdel -r 'username'
, the-r
option removes the user's home directory and mail spool. sudo passwd -l 'username'
is used to lock the password of the specified user.sudo usermod -a -G Gname Uname
adds the user to a specified group.
Also Read: Advantages of using Linux
5. Searching
Command | Description |
---|---|
grep pattern filename | Search for "pattern" in the file |
grep -i "indgeek" geeks.txt | Enables searching for a string case-insensitively |
grep -c "igeek" geeks.txt | Displays the count or number of matches |
grep -r pattern dir | Searches recursively for patterns in the directory |
locate filename | Finds all instances of a file |
grep -v "igeek" geeks.txt | Displays the unmatched lines with the searched pattern |
find . -name geeks.txt | Finds all files whose name is geeks.txt in the PWD |
find / -type d -name IndGeek | Finds directories whose name is IndGeek in the / directory |
Notes:
- Use
grep
to search for patterns within files. -i
ingrep -i "indgeek" geeks.txt
enables case-insensitive searching.-c
ingrep -c "igeek" geeks.txt
displays the count of matches.-r
ingrep -r pattern dir
searches recursively in the specified directory.locate filename
quickly finds all instances of a file.grep -v "igeek" geeks.txt
displays lines without the searched pattern.find . -name geeks.txt
finds files with a specific name in the present working directory.find / -type d -name IndGeek
finds directories with a specific name in the root directory.
6. Networking
Command | Description |
---|---|
ssh igeek@192.168.10.3 | Log into the remote host at a specific address as user 'igeek' |
ftp 192.168.10.3 | Connects to a remote FTP host |
ping indgeek.com | Ping and analyze network and host connections |
ifconfig -a | Display network information |
netstat | Shows active or listening ports |
whois domain | Get whois information for a domain |
dig domain | Grabs DNS information of a domain |
dig -x host | Reverse lookup host |
wget filename | Downloads a file |
wget url | Downloads a file from a specific URL |
put file | Uploads 'file' from local to the remote computer |
get file | Downloads 'file' from remote to local computer |
quit | Logout as a user |
Notes:
- Use
ssh
to log into a remote host. ftp
connects to a remote FTP host.ping
is used to analyze network and host connections.ifconfig -a
displays detailed network information.netstat
shows active or listening ports.whois domain
retrieves whois information for a domain.dig domain
grabs DNS information of a domain.dig -x host
performs a reverse lookup on a host.wget
is used to download files from the web.put
uploads a file from the local machine to the remote computer.get
downloads a file from the remote machine to the local computer.quit
is used to log out as a user.