20 Linux commands, take you out of the novice village!

Posted by p.utsav on Fri, 17 Dec 2021 07:42:26 +0100

Are you going to switch from Windows to Linux, or do you happen to switch to Linux? Ouch!!! What did I say? Why did you appear in my world. From my past experience, when I just used linux, commands, terminals and so on, it startled me. I'm worried about how many commands to remember to help me complete all my tasks.

There is no doubt that online documents, books, man pages and communities have helped me a lot, but I still believe that there is an article recording the secret of how to simply learn and understand commands. This inspired me to master Linux and make it easy to use. This article is the ladder to there.

1.ls command

The ls command means list directory contents. Running it is to list the contents of the folder, which may be files or folders.

root@tecmint:~# ls

Android-Games                     Music
Pictures                          Public
Desktop                           Tecmint.com
Documents                         TecMint-Sync
Downloads                         Templates

The "ls -l" command lists the contents of the folder in long listing fashion.

root@tecmint:~# ls -l

total 40588
drwxrwxr-x 2 ravisaive ravisaive     4096 May  8 01:06 Android Games
drwxr-xr-x 2 ravisaive ravisaive     4096 May 15 10:50 Desktop
drwxr-xr-x 2 ravisaive ravisaive     4096 May 16 16:45 Documents
drwxr-xr-x 6 ravisaive ravisaive     4096 May 16 14:34 Downloads
drwxr-xr-x 2 ravisaive ravisaive     4096 Apr 30 20:50 Music
drwxr-xr-x 2 ravisaive ravisaive     4096 May  9 17:54 Pictures
drwxrwxr-x 5 ravisaive ravisaive     4096 May  3 18:44 Tecmint.com
drwxr-xr-x 2 ravisaive ravisaive     4096 Apr 30 20:50 Templates

"ls -a" command will list all contents in the folder, including "." Hidden file at the beginning.

root@tecmint:~# ls -a

.           .gnupg          .dbus           .goutputstream-PI5VVW       .mission-control
.adobe                  deja-dup                .grsync                 .mozilla                    .themes
.gstreamer-0.10         .mtpaint                .thumbnails             .gtk-bookmarks              .thunderbird
.HotShots               .mysql_history          .htaccess       .apport-ignore.xml          .ICEauthority          
.profile                .bash_history           .icons                  .bash_logout                    .fbmessenger
.jedit                  .pulse                  .bashrc                 .liferea_1.8                .pulse-cookie          
.Xauthority     .gconf                  .local                  .Xauthority.HGHVWW      .cache
.gftp                   .macromedia             .remmina                .cinnamon                       .gimp-2.8
.ssh                    .xsession-errors    .compiz                 .gnome                          teamviewer_linux.deb        
.xsession-errors.old    .config                 .gnome2                 .zoncolor

Note: in Linux, files are marked with "." The beginning is to hide files, and every file, folder, device or command is treated as a file. ls -l command output:

1.d (represents the catalog)

2.rwxr-xr-x refers to the permissions of a file or directory to its users, the same group of users and other users.

3. The first ravisaive in the above example represents that the file belongs to the user ravisaive

4. The second ravisaive in the above example represents that the file belongs to the user group ravisaive

5.4096 represents a file size of 4096 bytes

6.May 8 01:06 represents the date and time of the last modification of the document

7. The last one is the name of the file / folder

2.lsblk command

"lsblk" is a list of block devices. In addition to RAM, block devices are displayed neatly in a standard tree output format.

root@tecmint:~# lsblk

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk
├─sda1   8:1    0  46.6G  0 part /
├─sda2   8:2    0     1K  0 part
├─sda5   8:5    0   190M  0 part /boot
├─sda6   8:6    0   3.7G  0 part [SWAP]
├─sda7   8:7    0  93.1G  0 part /data
└─sda8   8:8    0  89.2G  0 part /personal
sr0     11:0    1  1024M  0 rom

The "lsblk -l" command displays block devices in list format instead of tree format.

root@tecmint:~# lsblk -l

NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda    8:0    0 232.9G  0 disk
sda1   8:1    0  46.6G  0 part /
sda2   8:2    0     1K  0 part
sda5   8:5    0   190M  0 part /boot
sda6   8:6    0   3.7G  0 part [SWAP]
sda7   8:7    0  93.1G  0 part /data
sda8   8:8    0  89.2G  0 part /personal
sr0   11:0    1  1024M  0 rom

Note: lsblk is the most useful and easiest way to know the name of a newly inserted USB device, especially when you are dealing with disk / block devices on the terminal.

3.md5sum command

"md5sum" is to calculate and verify the MD5 information signature. MD5 checksum (commonly called hash) uses to match or verify the integrity of files, because files may change due to transmission errors, disk errors, or no malicious interference.

root@tecmint:~# md5sum teamviewer_linux.deb

47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

Note: users can use the signature information matching provided by the official and md5sum to detect whether the file has changed. Md5sum does not have sha1sum security, which we will discuss later.

4.dd command

The "dd" command represents converting and copying files. It can be used to convert and copy files. Most of the time, it is used to copy iso files (or any other files) to a USB device (or any other place), so it can be used to make USB starter.

root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync

Note: in the above example, the usb device is sdb1 (you should use the lsblk command to verify it, otherwise you will rewrite your disk or system). Please use the disk name carefully and avoid it.

The dd command will consume several seconds to several minutes according to the size and type of the file and the read-write speed of the usb device.

5.uname command

The "uname" command is short for Unix Name. Displays the machine name, operating system, and kernel details.

root@tecmint:~# uname -a

Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686

Note: uname displays kernel categories and uname -a displays details. The output above details uname -a

"Linux": the kernel name of the machine

"tecmint": node name of the machine

"3.8.0-19-generic": kernel release

"#30-Ubuntu SMP": kernel version

"i686": processor architecture

"GNU/Linux": operating system name

6.history command

The "history" command is history. It displays the history of all commands executed in the terminal.

root@tecmint:~# history

sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak
sudo add-apt-repository ppa:diesch/testing
sudo apt-get update
sudo apt-get install indicator-privacy
sudo add-apt-repository ppa:atareao/atareao
sudo apt-get update
sudo apt-get install my-weather-indicator
pwd
cd && sudo cp -r unity/6 /usr/share/unity/
cd /usr/share/unity/icons/
cd /usr/share/unity

Note: press and hold "CTRL + R" to search for executed commands, which can be completed automatically when you write commands.

(reverse-i-search)`if': ifconfig

7.sudo command

The "sudo" (super user do) command allows authorized users to execute commands of super users or other users. Specified by the security policy in the sudoers list.

root@tecmint:~# sudo add-apt-repository ppa:tualatrix/ppa

Note: sudo allows users to borrow the privileges of superuser, but the "Su" command actually allows users to log in as superuser. So sudo is safer than su.

It is not recommended to use sudo or su for daily use, because it may lead to serious errors. If you accidentally do something wrong, that is why there is a popular saying in the linux community:

"To err is human, but to really foul up everything, you need root password." "Anyone who is not a saint can make mistakes, but having a root password is really doomed."# translate

8.mkdir command

The "mkdir" (Make directory) command creates a new directory under a named path. However, if the directory already exists, it will return an error message "cannot create folder, folder already exists"

root@tecmint:~# mkdir tecmint

Note: a directory can only be created in a directory where the user has write permission. mkdir: the directory tecmint cannot be created because the file already exists. (don't be confused by files in the above output. You should remember what I said at the beginning - in linux, files, folders, drivers, commands and scripts are regarded as files)

9.touch command

The "touch" command represents updating the access and modification time of the file to the current time. The touch command creates a file only when it does not exist. If the file already exists, it updates the timestamp, but does not change the contents of the file.

root@tecmint:~# touch tecmintfile

Note: touch can be used to create nonexistent files in the directory where the user has write permission.

10.chmod command

The "chmod" command changes the mode bit of the file. chmod will change the file mode (permission) of each given file, folder, script, etc. according to the required mode.

There are three types of permissions in files (folders or others, we use files for simplicity)

Read (r)=4
Write(w)=2
Execute(x)=1

So if you want to give the file read-only permission, set it to '4'; Write only permission, set the permission to '2'; Execute permission only, set to 1; Read and write permissions, that is, 4 + 2 = 6, and so on. Now you need to set three kinds of user and user group permissions. The first is the owner, then the user's group, and finally other users.

rwxr-x--x   abc.sh

Here, the root permission is rwx (read / write and execute permission), The user group permission is r-x (only read and execute permissions, no write permissions), For other users, the permission is - x (only execute only permission) In order to change its permissions, it provides read, write and execute permissions for the owner, the user's group and other users.

root@tecmint:~# chmod 777 abc.sh

All three have read and write permissions

root@tecmint:~# chmod 666 abc.sh

The owner user has read-write and execution permissions, and the user's group and other users have only executable permissions

root@tecmint:~# chmod 711 abc.sh

Note: this command is one of the most useful commands for system administrators and users. In a multi-user environment or server, if the file is inaccessible for a user, this command can be used. If the wrong permission is set, it also provides authorized access.

11.chown command

The "chown" command changes the file owner and user group. Each file belongs to a user group and a user. In your directory, use "ls -l" and you'll see something like this.

root@tecmint:~# ls -l

drwxr-xr-x 3 server root 4096 May 10 11:14 Binary
drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Here, the directory Binary belongs to the user "server" and the user group "root", while the directory "Desktop" belongs to the user "server" and the user group "server" The "chown" command is used to change the ownership of the file, so it is only used to manage and provide the user and user group authorization of the file.

root@tecmint:~# chown server:server Binary

drwxr-xr-x 3 server server 4096 May 10 11:14 Binary
drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note: the files given by "chown" change the ownership of users and groups to new owners or existing users or user groups.

12.apt command

The Debian series is based on the "apt" command, which represents the Advanced Package Tool. Apt is an advanced package manager developed for Debian series systems (Ubuntu, Kubuntu, etc.). On Gnu/Linux system, it will automatically and intelligently search, install, upgrade and solve dependencies for packages.

root@tecmint:~# apt-get install mplayer

Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following package was automatically installed and is no longer required:
  java-wrappers
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4
Suggested packages:
  pulseaudio-esound-compat libroar-compat2 nvidia-vdpau-driver vdpau-driver mplayer-doc netselect fping
The following NEW packages will be installed:
  esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4 mplayer
0 upgraded, 9 newly installed, 0 to remove and 8 not upgraded.
Need to get 3,567 kB of archives.
After this operation, 7,772 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
root@tecmint:~# apt-get update

Hit http://ppa.launchpad.net raring Release.gpg                                          
Hit http://ppa.launchpad.net raring Release.gpg                                          
Hit http://ppa.launchpad.net raring Release.gpg                    
Hit http://ppa.launchpad.net raring Release.gpg                    
Get:1 http://security.ubuntu.com raring-security Release.gpg [933 B]
Hit http://in.archive.ubuntu.com raring Release.gpg                                                  
Hit http://ppa.launchpad.net raring Release.gpg                    
Get:2 http://security.ubuntu.com raring-security Release [40.8 kB]  
Ign http://ppa.launchpad.net raring Release.gpg                                                
Get:3 http://in.archive.ubuntu.com raring-updates Release.gpg [933 B]                          
Hit http://ppa.launchpad.net raring Release.gpg                                                              
Hit http://in.archive.ubuntu.com raring-backports Release.gpg

Note: the above command will change the overall system, so the root password is required (the view prompt is "#", not "$"). Compared with the yum command, Apt is more advanced and intelligent.

As the name implies, apt cache is used to search whether the package contains the sub package Mplayer, and apt get is used to install and upgrade all installed packages to the latest version.

13.tar command

The "tar" command is tape archive, which is very useful for creating archives of some files and decompressing them.

root@tecmint:~# tar -zxvf abc.tar.gz (remember that 'z' stands for. tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (remember that 'j' stands for. tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: "tar.gz" represents gzip archive, and "bar.bz2" uses bzip compression, which compresses better but slower.

14.cal command

"cal" (Calender), which is used to display the current month or the months in the future or any past year.

root@tecmint:~# cal

May 2013      
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Displays the month that has passed, February 1835

root@tecmint:~# cal 02 1835

   February 1835    
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28

Displays the future month, July 2145.

root@tecmint:~# cal 07 2145

     July 2145      
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Note: you don't need to go back and adjust the calendar for 50 years. You don't need to calculate the date of your birth or the date of your birthday [because its minimum unit is month, not day].

15.date command

The "date" command prints the current date and time using standard output, or you can drill down.

root@tecmint:~# date

Fri May 17 14:13:29 IST 2013
root@tecmint:~# date --set='14 may 2013 13:57'

Mon May 13 13:57:00 IST 2013

Note: this command is very useful in scripts, and time and date based scripts are more perfect. And change the date and time in the terminal to make you more professional!!! (of course, you need root permission to operate this, because it is an overall change of the system)

16.cat command

"cat" represents a connection, connecting two or more text files or printing the contents of files in standard output form.

root@tecmint:~# cat a.txt b.txt c.txt d.txt abcd.txt
root@tecmint:~# cat abcd.txt

contents of file abcd

Note: "> >" and ">" call additional symbols. They are used to append to the file instead of displaying on standard output. The ">" symbol deletes the existing file and creates a new file. Therefore, for security reasons, it is recommended to use "> >", which will be written to the file instead of overwriting or deleting.

Before delving further, I must let you know wildcards (you should know wildcards, which appear in most TV shows). Wildcards are a shell feature that makes the command line more powerful than any GUI file manager! As you can see, in a graphics file manager, if you want to select a large group of files, you usually have to use your mouse to select them. This may feel very simple, but in fact, this situation is very frustrating!

For example, suppose you have a directory with many, many types of files and subdirectories, and then you decide to move all HTML files with "Linux" in their file names to another directory. How to do this simply? If the directory contains a large number of HTML files with different names, your task is huge, not simple.

In LInux CLI, this task is very simple, just like moving only one HTML file, because there are wildcards in the shell. These are special characters that allow you to select file names that match a certain character pattern. It helps you choose, even if there are only a few characters in a large number of file names, and in most cases, it is simpler than selecting files with a mouse.

Here is a list of common wildcards:

Wildcard Matches
   *            Zero or more characters
   ?            Exactly one character
[abcde]             Exactly one character in the enumeration
 [a-e]          Exactly one character in the given range
[!abcde]        No character is in the enumeration
[!a-e]          None of the characters are in the given range
{debian,linux}      An entire word that happens to be in the given option

! It's called non, with '!' The reverse string of is true.

17.cp command

"Copy" is copy. It copies a file from one place to another.

root@tecmint:~# cp /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)

Note: cp is the most commonly used command in shell scripts, and it can use wildcards (described in the previous block) to customize the copy of the required files.

18.mv command

The "mv" command moves files from one place to another.

root@tecmint:~# mv /home/user/Downloads abc.tar.gz /home/user/Desktop (Return 0 when sucess)

Note: the mv command can use wildcards. mv should be used with caution, because moving system or unauthorized files will not only cause security problems, but also system crash.

19.pwd command

"pwd" (print working directory) displays the full path of the current working directory in the terminal.

root@tecmint:~# pwd

/home/user/Desktop

Note: this command is not often used in scripts, but for novices, when they lose their path in the terminal after connecting to nux for a long time, it is definitely a life-saving straw.

20.cd command

Finally, the frequently used "cd" command represents a directory change. It changes the working directory in the terminal to perform, copy, move, read, write and so on.

root@tecmint:~# cd /home/user/Desktop
server@localhost:~$ pwd

/home/user/Desktop

Note: when switching directories in the terminal, CD will play its role. "Cd ~" will change the working directory to the user's home directory, and it is very useful when the user finds that he has lost his path in the terminal. “cd ..” Switch from the current working directory to the parent directory (of the current working directory).

These commands are sure to make you comfortable on Linux. But this is not the end. Soon, I will write some other useful commands for intermediate users. For example, if you skillfully use these commands, cheer, boy, you will find that you have been promoted from a small white level to an intermediate user. In the next article, I will introduce commands such as "kill", "ps","grep" and so on. Look forward to it. I won't let you down.