Useful Linux Commands
We are all familiar with basic Linux commands such as pwd, ls, cd etc. Other than that given below are a few more commands that we might find useful in our day to day work.
1. Unzip a compressed file (.zip, .tar.xz, .tar.gz)
In Linux compressed files (zip files) come in different formats such as .zip, .tar.xz, .tar.gz etc. Here are some useful commands to unzip these files.
> Unzip a .zip file
Command: unzip file.zip -d /path-to-unzip/
Example: unzip myfile.zip -d /dest/bin
> Unzip a .tar.xz file
Command: tar -C /dest/ -xf file.tar.xz
Example: tar -C /usr/local -xf node-v16.15.1-linux-s390x.tar.xz
> Unzip a .tar.gz file
Command: tar -C /dest/ -xzf file.tar.gz
Example: tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz
2. Download a file from a URL
In order to download a file from a specific URL execute the wget command with the url as the parameter as:
Command: wget <download-url>
Example: wget https://go.dev/dl/go1.17.11.linux-s390x.tar.gz
3. Create a symbolic link (symlink) to a file
A symbolic link is similar to a Windows shortcut that points to another file or folder. In order to create a symlink refer the below example:
Command: ln -s <path-to-file-or-folder> <location>/<symlink-name>
Example: ln -s /usr/local/nodejs/bin/node /usr/bin/node
The above command creates a symlink called node in the directory /usr/bin/ which points to the executable file node in directory /usr/local/nodejs/bin/
4. Search for a file with specific criteria
We can use the find command to search for files with different criteria.
Criteria: Search for a file named .gitignore in the current directory
Command: find . -name ".gitignore" -type f
Criteria: Search for all files containing text "RMF" in the current directory
Command: grep -Ril "RMF" .
Here:
i
stands for ignore case (optional).
l
stands for "show the file name, not the result itself".
- . stands for current directory
5. Executing a command from the history
Do you know that you can retrieve and execute previously executed commands in your terminal with the history command?
Command: history
Displays a list of commands we have executed in our terminal
To execute a specific command just type the character ! with the line numberExample: !7 prints the current working directory
0 comments: