20 Commands That Are Very Useful for Linux Newbies

Are you planning to switch from Windows to Linux, or have you just switched to Linux? Oops!!! What am I saying — whatever reason brought you into my world. From my past experience, when I first started using Linux, commands, terminals and all that really scared me. I worried about how many commands I needed to memorize to help me complete all my tasks. Undoubtedly, online documentation, books, man pages, and the community helped me a great deal, but I still firmly believe there is an article that records the secret to easily learning and understanding commands. This motivated me to master Linux and make it easy to use. This article is the stepping stone to getting there.

Lesus

Lesus
Translated 4 days ago

4people liked

Upvote Nice translation!

1. ls Command

The ls command stands for List Directory Contents. Running it lists the contents of a folder, which could be files or folders.

1 root@tecmint:~# ls
2  
3 Android-Games                     Music
4 Pictures                          Public
5 Desktop                           Tecmint.com
6 Documents                         TecMint-Sync
7 Downloads                         Templates

The “ls -l” command lists the contents of a folder in long listing fashion.

01 root@tecmint:~# ls -l
02  
03 total 40588
04 drwxrwxr-x 2 ravisaive ravisaive     4096 May  8 01:06 Android Games
05 drwxr-xr-x 2 ravisaive ravisaive     4096 May 15 10:50 Desktop
06 drwxr-xr-x 2 ravisaive ravisaive     4096 May 16 16:45 Documents
07 drwxr-xr-x 6 ravisaive ravisaive     4096 May 16 14:34 Downloads
08 drwxr-xr-x 2 ravisaive ravisaive     4096 Apr 30 20:50 Music
09 drwxr-xr-x 2 ravisaive ravisaive     4096 May  9 17:54 Pictures
10 drwxrwxr-x 5 ravisaive ravisaive     4096 May  3 18:44 Tecmint.com
11 drwxr-xr-x 2 ravisaive ravisaive     4096 Apr 30 20:50 Templates

The "ls -a" command lists all contents in a folder, including hidden files starting with ".".

01 root@tecmint:~# ls -a
02  
03 .           .gnupg          .dbus           .goutputstream-PI5VVW       .mission-control
04 .adobe                  deja-dup                .grsync                 .mozilla                    .themes
05 .gstreamer-0.10         .mtpaint                .thumbnails             .gtk-bookmarks              .thunderbird
06 .HotShots               .mysql_history          .htaccess       .apport-ignore.xml          .ICEauthority          
07 .profile                .bash_history           .icons                  .bash_logout                    .fbmessenger
08 .jedit                  .pulse                  .bashrc                 .liferea_1.8                .pulse-cookie           
09 .Xauthority     .gconf                  .local                  .Xauthority.HGHVWW      .cache
10 .gftp                   .macromedia             .remmina                .cinnamon                       .gimp-2.8
11 .ssh                    .xsession-errors    .compiz                 .gnome                          teamviewer_linux.deb         
12 .xsession-errors.old    .config                 .gnome2                 .zoncolor

Note:在LinuxIn Linux, files starting with“.”are hidden files, and every file, folder, device or command is treated as a file.ls -l Command output:

  1. d (Indicates it is a directory).
  2. rwxr-xr-x are the permissions for the owning user, the owning group, and other users.
  3. In the example above, the firstravisaive represents the file belongs to user ravisaive
  4. In the example above, the secondravisaiverepresents the file belongs to user 组ravisaive
  5. 4096 represents the file size is 4096 bytes.
  6. May 8 01:06 represents the date and time of the last modification.
  7. The last part is the name of the file/folder.

more"ls"See examples at 15 Basic ‘ls’ Command Examples in Linux

Lesus

Lesus
Translated 4 days ago

3people liked

Upvote Nice translation!

Other translations (1)

2. lsblk Command

"lsblk"lists block devices. Apart fromRAM, it displays in a standard tree-likeoutputformat, neatly showing block devices.

01 root@tecmint:~# lsblk
02  
03 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
04 sda      8:0    0 232.9G  0 disk
05 ├─sda1   8:1    0  46.6G  0 part /
06 ├─sda2   8:2    0     1K  0 part
07 ├─sda5   8:5    0   190M  0 part /boot
08 ├─sda6   8:6    0   3.7G  0 part [SWAP]
09 ├─sda7   8:7    0  93.1G  0 part /data
10 └─sda8   8:8    0  89.2G  0 part /personal
11 sr0     11:0    1  1024M  0 rom

lsblk -l”command displays block devices in list format(rather than tree format)。

01 root@tecmint:~# lsblk -l
02  
03 NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
04 sda    8:0    0 232.9G  0 disk
05 sda1   8:1    0  46.6G  0 part /
06 sda2   8:2    0     1K  0 part
07 sda5   8:5    0   190M  0 part /boot
08 sda6   8:6    0   3.7G  0 part [SWAP]
09 sda7   8:7    0  93.1G  0 part /data
10 sda8   8:8    0  89.2G  0 part /personal
11 sr0   11:0    1  1024M  0 rom

Note:lsblkis the most useful and simplest way to understandinsert的USBdevice names, especially when working with disk/block devices in the terminal.

3. md5sum Command

md5sum”calculates and verifiesMD5message digests.md5 checksum(Commonly known as hash)is used to match or verify file integrity, as files may change due to transmission errors, disk errors, or non-malicious interference.

1 root@tecmint:~# md5sum teamviewer_linux.deb
2  
3 47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

Note: Users can compare the officially provided and md5sum generated signatures to detect if a file has changed. md5sum is not as secure as sha1sum, which we will discuss later.

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

4. dd Command

dd”command stands for convert and copy files. It can be used to convert and copy files, most commonly used to copyiso文件(or any other file)to ausbdevice(or any other location), so it can be used to createUSBlauncher。

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

Note: In the above example,usbdevice issdb1(You should uselsblkcommand to verify it, otherwise you may overwrite your disk or system), use disk names with caution.

dd command during execution, depending on file size and type and usband device read/write speed, may take from a few seconds to several minutes.

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

5. uname Command

"uname"command isUnix Nameshort for. Displays machine name, OS and kernel details.

1 root@tecmint:~# uname -a
2  
3 Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux

Note: unameshows kernel type, uname -ashows detailed info. Aboveoutputdetailsuname -a

  1. Linux“: machine kernel name
  2. tecmint“: machine node name
  3. 3.8.0-19-generic“: kernel release version
  4. #30-Ubuntu SMP“: kernel version
  5. i686“: processor architecture
  6. GNU/Linux“: OS name

6. history Command

history”command is the history. It shows the history of all commands executed in the terminal.

01 root@tecmint:~# history
02  
03  sudo add-apt-repository ppa:tualatrix/ppa
04  sudo apt-get update
05  sudo apt-get install ubuntu-tweak
06  sudo add-apt-repository ppa:diesch/testing
07  sudo apt-get update
08  sudo apt-get install indicator-privacy
09  sudo add-apt-repository ppa:atareao/atareao
10  sudo apt-get update
11  sudo apt-get install my-weather-indicator
12  10 pwd
13  11 cd && sudo cp -r unity/6 /usr/share/unity/
14  12 cd /usr/share/unity/icons/
15  13 cd /usr/share/unity

Note: Pressing “CTRL + R” allows you to search through previously executed commands, and it can auto-complete as you type.

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

Lesus

Lesus
Translated 4 days ago

0people liked

Upvote Nice translation!

7. sudo Command

sudo”(super user do)command allows authorized users to execute superuser or other user commands. Through thesudoerslist security policy to specify.

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

Note:sudo allows users to borrow superuser privileges, whereas"su"command actually allows users to log in as superuser. Thereforesudosusafer。
is not recommendedsudoorsufor daily use, as it may lead to serious errors if you accidentally do something wrong, which is why in thelinuxcommunity there is a saying:

“To err is human, but to really foul up everything, you need root password.”

 

 

“To err is human, but to really foul up everything, you need root password.” # 译

8. mkdircommand

mkdir”(Make directory)command creates a new directory at the named path. However, if the directory already exists, it returns an error message"cannot create directory, directory already exists"("cannot create folder, folder already exists")

1 root@tecmint:~# mkdir tecmint

Note: Directories can only be created in directories where the user has write permission.mkdir: cannot create directory`tecmint`, because the file already exists. (In the output abovedon’t be confused by the fileconfused, remember what I said at the beginning-在linuxin Linux, files, folders, drives, commands, scripts are all treated as files)

Lesus

Lesus
Translated 4 days ago

2people liked

Upvote Nice translation!

9. touch Command

touch”command stands for updating file access and modification times to the current time.touchcommand only creates the file if it does not exist. If the file already exists, it updates the timestamp but does not change the content.

1 root@tecmint:~# touch tecmintfile

Note:touch canis used to create non-existent files in directories where the user has write permission.

10. chmod Command

chmod”command is for changing file mode bits.chmodchanges each given file, folder, script etc. according to the requested mode(permissions).

There are 3 types of permissions in files (folders or other, for simplicity, we’ll use file):

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

So if you want to give a file read-only permission, set it to'4';write-only permission, set to'2';execute-only permission, set to1; read-write permission, that is4+2 = 6, and so on.

Now you need to set permissions for 3 types of users and groups. The first is the owner, then the group the user belongs to, and finally other users.

1 rwxr-x--x   abc.sh

hererootpermissions are rwx(Read, write and execute permissions),
Group permissions are r-x (read and execute only, no write permission)
For other users, permissions are –x(execute only)

To change its permissions, providing read, write, and execute permissions for the owner, the group, and other users.

1 root@tecmint:~# chmod 777 abc.sh

All three have only read and write permissions.

1 root@tecmint:~# chmod 666 abc.sh

The owner has read, write, and execute permissions, while the group and other users have only execute permissions.

1 root@tecmint:~# chmod 711 abc.sh

Note: For system administrators and users, this command is one of the most useful commands. In a multi-user environment or on a server, if a file is set to be inaccessible for a certain user, this command can solve it. If wrong permissions are set, it may provide unauthorized access.

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

11. chown Command

chown”command changes file owner and group. Every file belongs to a user group and a user. In your directory, using"ls -l",you will see something like this.

1 root@tecmint:~# ls -l
2  
3 drwxr-xr-x 3 server root 4096 May 10 11:14 Binary
4 drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Here, the directoryBinarybelongs to user"server",and user group"root",while directory"Desktop"belongs to user“server”and user group"server"

chown”command is used to change file ownership, so it is only used to manage and provide file user and group authorization.

1 root@tecmint:~# chown server:server Binary
2  
3 drwxr-xr-x 3 server server 4096 May 10 11:14 Binary
4 drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note:“chown”changes ownership of the given file to the new owner or existing user or user group.

Lesus

Lesus
Translated 4 days ago

0people liked

Upvote Nice translation!

12. apt Command

Debianseries with“apt”command as the foundation,“apt”representsAdvanced Package Tool。APTis aDebianseries systems (Ubuntu,Kubuntuetc.) developed advanced package manager, inGnu/Linuxon the system,it will automatically and intelligently search, install, upgrade, and resolve dependencies for packages.

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

01 root@tecmint:~# apt-get update
02  
03 Hit http://ppa.launchpad.net raring Release.gpg                                          
04 Hit http://ppa.launchpad.net raring Release.gpg                                          
05 Hit http://ppa.launchpad.net raring Release.gpg                     
06 Hit http://ppa.launchpad.net raring Release.gpg                     
07 Get:1 http://security.ubuntu.com raring-security Release.gpg [933 B]
08 Hit http://in.archive.ubuntu.com raring Release.gpg                                                  
09 Hit http://ppa.launchpad.net raring Release.gpg                     
10 Get:2 http://security.ubuntu.com raring-security Release [40.8 kB]  
11 Ign http://ppa.launchpad.net raring Release.gpg                                                 
12 Get:3 http://in.archive.ubuntu.com raring-updates Release.gpg [933 B]                           
13 Hit http://ppa.launchpad.net raring Release.gpg                                                               
14 Hit http://in.archive.ubuntu.com raring-backports Release.gpg

Note: The above commands will cause system-wide changes, so root password is required (look for the prompt "#" instead of “$”). Compared to the yum command, Apt is more advanced and intelligent.

As the name suggests,apt-cacheis used to search whether a package contains sub-packagesmplayer, apt-getis used to install and upgrade all installed packages to the latest version.

aboutapt-get 和 apt-cacheFor more information on the command, see 25 APT-GET and APT-CACHE Commands

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

13. tar Command

tar”command stands for tape archive(Tape Archive), useful for creating archives of files and extracting them.

1 root@tecmint:~# tar -zxvf abc.tar.gz (remember'z'represents.tar.gz)

1 root@tecmint:~# tar -jxvf abc.tar.bz2 (remember'j'represents.tar.bz2)

1 root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: "tar.gz"means usinggziparchive,“bar.bz2”usebzipcompression, which compresses better but is slower.

learn more"tar command"for examples, see 18 Tarnaming examples

14. cal Command

cal”(Calender), it is used to display the month of the current or any year in the future or past.

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

displays a past month, February 1835

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

displays a future month, July 2145.

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

Note: You don’t need to adjust the calendar backwards50years, no complex calculation needed for your birth date or when your birthday falls,[because its smallest unit is month, not day]。

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

15. date Command

date”command prints the current date and time to standard output, and can also be customized.

1 root@tecmint:~# date
2  
3 Fri May 17 14:13:29 IST 2013

1 root@tecmint:~# date --set='14 may 2013 13:57'
2  
3 Mon May 13 13:57:00 IST 2013

Note: This command is very useful in scripts, and time and date based scripts are even better. Moreover, changing the date and time in the terminal makes you look more professional!!! (Of course you need root privileges to operate this, as it is a system-wide change)

16. cat Command

cat”stands for concatenate (Concatenation), joining two or more text files or printing file contents to standard output.

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

1 root@tecmint:~# cat abcd.txt
2 ....
3 contents of file abcd
4 ...

Note:“>>”和“>”calls the append symbol. They are used to append to files instead of displaying on standard output.“>”symbol will delete existing files and create a new one. Therefore for safety reasons, it is recommended to use“>>”, which writes to files without overwriting or deleting.

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

Before diving deeper, I must let you know about wildcards (you should know wildcards, they appear in most TV talent shows). Wildcards are a feature of the shell, and make any GUICompared to a file manager, it makescommand line more powerful! As you can see, in a graphical file manager, if you want to select a large group of files, you usually have to use your mouse to select them. This may seem simple, but in fact, this situation is quite frustrating!

For example, suppose you have a directory with many, many files of various types and subdirectories, and you decide to move all HTML files whose filenames contain the word “Linux” to another directory. How do you easily accomplish this? If the directory contains a large number of differently named HTML files, your task is huge, not simple.

In the Linux CLI, this task is as simple as moving just one HTML file, thanks to shell wildcards. These are special characters that allow you to select filenames matching certain character patterns. It helps you select, even among a large number of filenames with only a few characters, and in most cases, it is simpler than using a mouse to select files.

Here is a list of commonly used wildcards:

1 Wildcard Matches
2    *            zero or more characters
3    ?            exactly one character
4 [abcde]             exactly one character from the list
5  [a-e]          exactly one character within the given range
6 [!abcde]        any character not in the list
7 [!a-e]          any character not in the given range
8 {debian,linux}      exactly one whole word from the given options

! called NOT, with'!'the inverted string is true

For more, readLinux cat command examples 13 Linux cat Command Examples

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

17. cp Command

“copy” means to copy. It copies a file from one place to another.

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

Note: cp,在shellis one of the most commonly used commands in scripts, and it can use wildcards (described in the previous section) to customize file copying.

18. mv Command

mv”command moves files from one location to another.

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

Note:mv command can use wildcards.mvUse with caution, as moving system or unauthorized files can not only cause security issues but may crash the system.

19. pwd Command

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

1 root@tecmint:~# pwd
2  
3 /home/user/Desktop

Note: This command is not frequently used in scripts, but for beginners, when connecting tonuxafter a long timein the terminallosing track of the path,this is absolutely a lifesaver.

Lesus

Lesus
Translated 4 days ago

1people liked

Upvote Nice translation!

20. cd Command

Finally, the frequently used“cd”command stands for change directory. It changes the working directory in the terminal for execution, copying, moving, reading, writing, etc.

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

Note: When switching directories in the terminal,cdcomes into its own.“cd ~”changes the working directory to the home directory, and is very useful when you find yourself lost in the terminal.“cd ..”switch from the current working directory to(of the current working directory)parent directory。

These commands will definitely make you comfortable on Linux. But this is not the end. Soon, I will write some other useful commands targeted at intermediate useruseful commands. For example, if you are proficient with these commands, congratulations, you have leveled up from beginner to intermediate user. In the next article, I will introduce commands like“kill”,"ps","grep"and more, stay tuned, I won’t let you down.

Leave a Comment

Your email address will not be published.