Top 30 Linux Commands Everyone Should Know – Part II

Top 30 Linux Commands Everyone Should Know – Part II

Linux Commands: Part II

In Part 1 of our Linux command series, we covered some basic commands that you can use in your daily coding tasks. In Part 2, we will build on that knowledge by introducing additional basic to intermediate commands to further enhance your skills.

16. touch

The touch command is used to create an empty file or updates the timestamp of an existing file.

# To create a python file
admin@dotsperpixels.com ~ % touch app.py
# To create a text file under tmp folder
admin@dotsperpixels.com ~ % touch tmp/sample.txt
jithinm@Jithins-MacBook-Pro ~ % echo "Hello, World"
Hello, World

17. echo

Used to print something on the terminal.

admin@dotsperpixels.com ~ % echo "Hello, World"
Hello, World

18. cat

Displays the file content in the user’s terminal. The cat command will show the entire content of the file on the terminal screen.

sample.txt

admin@dotsperpixels.com ~ % cat sample.txt
This is a sample text.

19. less

Unlike cat, less allows you to view a file with pagination. For smaller files, less will function similarly to cat.

admin@dotsperpixels.com ~ % less sample.txt
This is a sample text.

20. head

The head command will let you display the beginning of a file content. Additionally, it allows you to specify the number of lines to display.

# To list the first page of a log file.
admin@dotsperpixels.com ~ % head error.log
# To list the first 25 lines of a log file.
admin@dotsperpixels.com ~ % head -n 25 error.log

21. tail

As the name suggest it will list the last few lines of a file content. You can optionally specify the number of lines to be shown.

# To list the last page of a log file.
admin@dotsperpixels.com ~ % tail error.log
# To list the last 25 lines of a log file.
admin@dotsperpixels.com ~ % tail -n 25 error.log

22. chmod

Used to modify the permission of a file or directory. It allows you to set Read, Write, and Execute permissions for the file owner, group, and others.

File Permission:

admin@dotsperpixels.com tmp % ls -la
total 0
drwxr-xr-x   4 admin  dotsperpixels   128 Aug  4 02:09 .
drwxr-x---+ 32 admin  dotsperpixels  1024 Aug  4 02:10 ..
drwxr-xr-x   2 admin  dotsperpixels    64 Aug  4 02:09 images
-rw-r--r--   1 admin  dotsperpixels     0 Aug  4 02:09 sample.txt

How to read permission:


drwxr-xr-x
d : In the first column, the letter d indicates that the item is a directory, while a dash - indicates that it is a regular file.
r : Read
w : Write
x : Execution
- : A dash(-) in the remaining positions(position 2-10) indicates a missing permission.
# Giving all(rwx) permissions to all the users
admin@dotsperpixels.com tmp % chmod -R 777 .
admin@dotsperpixels.com tmp % ls -la
total 0
drwxr-xr-x   4 admin  dotsperpixels   128 Aug  4 02:09 .
drwxr-x---+ 32 admin  dotsperpixels  1024 Aug  4 02:10 ..
drwxrwxrwx   2 admin  dotsperpixels    64 Aug  4 02:09 images
-rwxrwxrwx   1 admin  dotsperpixels     0 Aug  4 02:09 sample.txt
  • Here 777 indicates all the permission to all the users(Owner, Group and Other).

23. chown

To change the owner and the group of the file or directory.

# Change the owner to root and group to www-data for images folder
admin@dotsperpixels.com tmp % chown -R root:www-data images
# Change the owner to root and group to www-data for sample.txt
admin@dotsperpixels.com tmp % chown root:www-data sample.txt
admin@dotsperpixels.com tmp % ls -la
total 0
drwxr-xr-x   4 root  www-data   128 Aug  4 02:09 .
drwxr-x---+ 32 root  www-data  1024 Aug  4 02:10 ..
drwxrwxrwx   2 root  www-data    64 Aug  4 02:09 images
-rwxrwxrwx   1 root  www-data     0 Aug  4 02:09 sample.txt

24. grep

This is used to search a pattern of text data. This is usually performed on top of a textual output. By default, this is case sensitive in nature.

# For searching list of images with .png extension in a given directory
admin@dotsperpixels.com tmp % ls -la | grep .png
# For searching a txt file for a keyword
admin@dotsperpixels.com tmp % cat sample.txt | grep root
# Case-insensitive keyword search
admin@dotsperpixels.com tmp % cat sample.txt | grep -i root
  • -i : Used to mark case-insensitive(regardless of uppercase or lowercase) pattern search.

25. df

This is used to display the amount of disk space used and available on the file systems.

admin@dotsperpixels.com tmp % df -lha
Filesystem        Size    Used   Avail Capacity iused ifree %iused  Mounted on
/dev/disk3s3s1   460Gi   9.6Gi   372Gi     3%    404k  3.9G    0%   /
/dev/disk3s6     460Gi   9.0Gi   372Gi     3%       9  3.9G    0%   /System/Volumes/VM
/dev/disk3s4     460Gi   5.8Gi   372Gi     2%    1.1k  3.9G    0%   /System/Volumes/Preboot
/dev/disk3s2     460Gi    46Mi   372Gi     1%      52  3.9G    0%   /System/Volumes/Update
/dev/disk2s2     500Mi   6.0Mi   481Mi     2%       1  4.9M    0%   /System/Volumes/xarts
/dev/disk2s1     500Mi   6.2Mi   481Mi     2%      35  4.9M    0%   /System/Volumes/iSCPreboot
/dev/disk2s3     500Mi   2.4Mi   481Mi     1%      46  4.9M    0%   /System/Volumes/Hardware
/dev/disk3s1     460Gi    64Gi   372Gi    15%    702k  3.9G    0%   /System/Volumes/Data
  • h – make the result human readable format.

26. du

To display the storage usage of an individual file or directory. For a directory, it will list all the individual files under the folder.

admin@dotsperpixels.com tmp % du -lha
2.1M	projects/python
2.1M	projects
2.0K    sample.txt

27. top

This is used to list the running process on your Linux operating system.

28. kill

To kill or terminate a process by its id(PID)

admin@dotsperpixels.com tmp % kill 50678

29. wget

This command will allow you to download files from the internet into your local file system.

# Download a file using the provided URL.
admin@dotsperpixels.com tmp % wget http://mywebsite.com/file.txt
# Download the file into the specified name
admin@dotsperpixels.com tmp % wget -O new_name.txt http://mywebsite.com file.txt
# Download a file in background
admin@dotsperpixels.com tmp % wget -b http://mywebsite.com/file.txt
# To Continue a partially downloaded file.
admin@dotsperpixels.com tmp % wget -c http://mywebsite.com/file.txt
# To limit the download speed to 500kpbs.
admin@dotsperpixels.com tmp % wget --limit-rate=500k http://mywebsite.com/file.txt

How cool it is to download an entire site into your local, Try this:

# Download an Entire website.
admin@dotsperpixels.com tmp % wget --mirror http://mywebsite.com

30. curl

The curl command is used to transfer the data to/ from a server using various protocols such as HTTP, HTTPS, FTP, and SCP. It facilitates making requests to web servers, downloading and uploading files, and more.

# Download a file using the provided URL.
admin@dotsperpixels.com tmp % curl -O http://mywebsite.com/file.txt
# Download the file into the specified name
admin@dotsperpixels.com tmp % curl -o new_name.txt http://mywebsite.com/file.txt
# Send a GET Request Call
admin@dotsperpixels.com tmp % curl http://mywebsite.com/file.txt
# Send a POST Request with data
admin@dotsperpixels.com tmp % curl -d "param1=value1&param2=value2" -X POST http://mywebsite.com/file.txt
# Show only the HTTP headers
admin@dotsperpixels.com tmp % curl -I http://mywebsite.com/file.txt

You can apply alias to almost all the script you used in a daily basis. Try to create and use your own entries today itself.

Bonus

Now that you’re here, here are some bonus commands to enhance your Linux command line skills:

31. uname – To display system information.

32. whoami – To display user name.

33. free – Display free memory information.

34. passwd – Change the password of the current user.

35. adduser – To add a new user to the system.

36. ping – To check the network activity to an IP address or host name.

37. netstat – To display network status.

38. scp – To securely copy file content between to remote server.

39 . ssh – This command is used to securely connect to a remote server over a network.

40. htop – The htop is similar to top command but will give more interactive and color coded display output.

# To display system information
uname -a
# To display user name
whoami
# Display free memory space in human readable format
free -h
# Change password of the current user
passwd
# Add a user from terminal
sudo adduser new_user
# To check the network connectivity to a host or IP address
ping hostname/ipaddress
# To display various network connection information
netstat
# Securely copy content to remote server
scp /path/to/localfile.txt username@remotehost:/path/to/remote/directory/
# Securely connect to your remote system
ssh username@hostname
# To display system process in more user-friendly way
htop

Conclusion

In this two-part Linux command series, you’ve explored a range of basic to intermediate commands and learned how to apply them to real-life scenarios. While we’ve covered essential commands that are useful for everyday tasks, there are many more commands and techniques to discover. Continue exploring to expand your command-line skills and uncover additional tools that can further enhance your productivity.

Share your list of commands that you don’t find in the above list, in the comments below.

Credits :
Photo by Gabriel Heinzer on Unsplash



1 thought on “Top 30 Linux Commands Everyone Should Know – Part II”

Leave a Reply