Tips: Common CLI commands for beginners

Share your own howto's etc. Not for support questions!
Post Reply
Message
Author
User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Tips: Common CLI commands for beginners

#1 Post by Hallvor »

Why bother with the command line interface (CLI)?

Using the CLI makes it easier to follow and give advice. While I am not advocating feeding your system with commands you do not understand, it is easier to copy and paste a command than clicking around in a GUI that is changing from version to another.

Although new commands are introduced from time to time, the original commands almost always remain the same.



Arch

The arch command is used to print the machine's architecture. For example:

Code: Select all

$ arch
x86_64

Cal/ncal

The cal and ncal commands will display a calendar:

Code: Select all

$ cal
   Februar 2019       
su må ty on to fr la   
               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        
Cat
The cat command prints the information of a file.

Code: Select all

$ cat debian.txt
Debian is awesome
cd
The cd command - change directory – allows you to navigate to a given directory.

Code: Select all

$ cd /home/hallvor/Music
chgrp
The chgrp command changes the group ownership of a file. Use group name as first argument and the name of the file as second argument.

Code: Select all

$ chgrp  debian debian.txt
chmod
The chmod command changes access permissions for a file, for instance making it executable:

Code: Select all

$ chmod +x debian.bin
Chown
The chown command changes ownership and group of a file. This example changes ownership and group to root:

Code: Select all

# chown root:root debian.txt
Clear
The clear command clears the terminal screen.

Code: Select all

$ clear
Cp
The cp command copies files and directories. This command will copy debian.txt to my documents folder in my home directory:

Code: Select all

$ cp debian.txt /home/hallvor/Documents
Date
The date command can print or set the system date and time.

Code: Select all

$ date 
må. 18. feb. 18:58:56 +0100 2019

Df
The df command displays the file system disk space usage in output.

Code: Select all

$ df 
Filsystem                             1K-blokker    Brukt Tilgjengelig Bruk% Montert på 
udev                                     3918824        0      3918824    0% /dev 
tmpfs                                     786256    17624       768632    3% /run 
/dev/mapper/debian--thinkpad--vg-root  236889936 44816920    179969952   20% / 
tmpfs                                    3931260    33948      3897312    1% /dev/shm 
tmpfs                                       5120        4         5116    1% /run/lock 
tmpfs                                    3931260        0      3931260    0% /sys/fs/cgroup 
/dev/sda1                                 240972    38829       189702   17% /boot 
tmpfs                                     786252        0       786252    0% /run/user/113 
tmpfs                                     786252       28       786224    1% /run/user/1000

Dir
The dir command lists directory contents.

Code: Select all

$ dir
Movies Documents debian.txt
Dpkg
The dpkg tool is a CLI package manager for Debian. To install a downloaded deb-file:

Code: Select all

# dpkg -i filename.deb
Exit
The exit command will exit the shell

Code: Select all

$ exit

Find

The find command will search for files in a directory and in its sub-directories.

Code: Select all

$ find debian*
debian
debian2
debian.txt
Free
The free command displays the amount of free and used memory in the system.

Code: Select all

$ free 
             total        used        free      shared  buff/cache   available 
Mem:        7862524     1513612      708188      258528     5640724     5816176 
Swap:       8069116           0     8069116
Grep
The grep command searches for a specified content in a file (or files) and displays the content:

Code: Select all

$ grep "Debian" debian.txt
Debian rocks!
Groups
Groups displays the name of groups a user is part of.

Code: Select all

$ groups hallvor 
hallvor : hallvor cdrom floppy audio dip video plugdev netdev bluetooth lpadmin

History
The history command displays the history of your shell commands.

Code: Select all

$ history
Kill
The kill command kills a process by sending the TERM signal to it.

Code: Select all

# kill [process-id]

Killall

The killall command kills a process by name.

Code: Select all

# killall konsole
Locate
The locate command helps user find a file by name. In Debian you may have to do the following to make the command work:

Code: Select all

# apt install locate && updatedb
Then, for instance:

Code: Select all

$ locate *.txt
/home/hallvor/debian.txt
/home/hallvor/test/debian.txt
ls
The ls command shows all non-hidden files, folders and directories.

Code: Select all

$ ls
Lscpu
The lscpu command displays the CPU architecture information:

Code: Select all

$ lscpu 
Arkitektur:            x86_64 
Op-tilstande for CPU:  32-bit, 64-bit 
Byterækkefølge:      Little Endian 
CPU'er:                4 
Tilkoblet cpu(er) liste:0-3 
Tråde per kerne:      2 
Kerner per sokkel:     2 
Sokler:                1 
NUMA-knuder:           1 
Leverandør-id:        GenuineIntel 
CPU-familie:           6 
Model:                 69 
Modelnavn:             Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz 
Modelserie:            1 
CPU MHz:               1204.980 
CPU maks. MHz:         3300,0000 
CPU min. MHz:          800,0000 
BogoMIPS:              5387.59 
Virtualisation:        VT-x 
L1d mellemlager:       32K 
L1i mellemlager:       32K 
L2 mellemlager:        256K 
L3 mellemlager:        4096K 
NUMA-knuder0 CPU'er:   0-3 
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dte
s64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb invpcid_single ssbd ibrs ibpb stibp kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 
avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts flush_l1d

Lspci
Prints detailed information about all PCI buses and devices in the system.

Code: Select all

$ lspci

Lsusb

Displays information about USB buses in the system and the devices connected to them.

Code: Select all

$ lsusb
Man
man lets you access the manual pages. For instance:

Code: Select all

$ man grep
Mkdir
The mkdir command lets you create directories.

Code: Select all

$ mkdir test
mv
The mv command (move) allows you to move a file or folder from the old location to the new location. (It can also be used to rename a file):

Code: Select all

$ mv /home/hallvor/debian.txt /home/hallvor/Dokument/debian.txt
Passwd
The passwd command changes passwords

Code: Select all

$ passwd hallvor
... for a user password, or

Code: Select all

# passwd root 
... to change the root password

Ping
The ping command is used to check if a system is up and responding.

Code: Select all

$ ping -c3 google.com 
PING google.com (216.58.211.14) 56(84) bytes of data. 
64 bytes from arn09s20-in-f14.1e100.net (216.58.211.14): icmp_seq=1 ttl=53 time=33.5 ms 
64 bytes from arn09s20-in-f14.1e100.net (216.58.211.14): icmp_seq=2 ttl=53 time=34.1 ms 
64 bytes from arn09s20-in-f14.1e100.net (216.58.211.14): icmp_seq=3 ttl=53 time=36.0 ms

rmdir

The rmdir (remove directory) command allows the user to remove an existing directory. For instance:

Code: Select all

$ rmdir test
... to remove an empty directory, or

Code: Select all

$ rmdir --ignore-fail-on-non-empty test
... to remove a directory and its contents


rm
The rm command (remove) will remove/delete files or directories with files in it. For instance:

Code: Select all

$ rm debian.txt
... or

Code: Select all

$ rm -r /home/hallvor/dokument
... to delete the documents folder and all the files and folders within it.

Su
The su (switch user) command lets you change user identity. The most common usage is to become root:

Code: Select all

$ su -
... and you can also use it to switch to another user

Code: Select all

# su - hallvor
Top
The top command lists running processes

Code: Select all

$ top
touch
The touch command makes an empty file

Code: Select all

$ touch debian.txt
Last edited by Hallvor on 2019-02-21 22:51, edited 8 times in total.
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

User avatar
Head_on_a_Stick
Posts: 13450
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Tips: Common CLI commands for beginners

#2 Post by Head_on_a_Stick »

Nice guide Hallvor, thanks.

One thing though:
Hallvor wrote:The su (switch user) command lets you change user identity. The most common usage is to become root:

Code: Select all

$ su
It is recommended to use this instead:

Code: Select all

su -
If plain `su` is used then the normal user's environment is maintained so the sbin directories will be missing from PATH (along with a few other differences), only `su -` attains a full root environment.

And just to note that another nice guide to basic command line usage can be read with

Code: Select all

man intro
Black Lives Matter

Debian buster-backports ISO image: for new hardware support

User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Re: Tips: Common CLI commands for beginners

#3 Post by Hallvor »

Thanks, Head_on_a_Stick!

I have updated it.
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

Bulkley
Posts: 6144
Joined: 2006-02-11 18:35

Re: Tips: Common CLI commands for beginners

#4 Post by Bulkley »

Agreed, that's a good guide, Hallvor. While I know and use most of them there are a couple new to me. Thanks for the refresher.

User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Re: Tips: Common CLI commands for beginners

#5 Post by Hallvor »

Bulkley wrote:Agreed, that's a good guide, Hallvor. While I know and use most of them there are a couple new to me. Thanks for the refresher.
You are welcome. :)
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

User avatar
None1975
Posts: 1019
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: Tips: Common CLI commands for beginners

#6 Post by None1975 »

Very good guide. Thanks for sharing it!
OS: Debian 10.3 Buster / WM: xmonad
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Re: Tips: Common CLI commands for beginners

#7 Post by Hallvor »

None1975 wrote:Very good guide. Thanks for sharing it!
Thank you! :)
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

User avatar
sunrat
Global Moderator
Global Moderator
Posts: 3659
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 3 times
Been thanked: 4 times

Re: Tips: Common CLI commands for beginners

#8 Post by sunrat »

Nice easy-to-follow guide and covers many of the most used commands.

Please check the dpkg entry. dpkg -i will install a package, not extract.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Re: Tips: Common CLI commands for beginners

#9 Post by Hallvor »

Thank you. I have edited it.
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

Re: Tips: Common CLI commands for beginners

#10 Post by sickpig »

Bookmarked
thanks for creating it

User avatar
Hallvor
Posts: 1175
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

Re: Tips: Common CLI commands for beginners

#11 Post by Hallvor »

sickpig wrote:Bookmarked
thanks for creating it
You are welcome.
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

User avatar
dotlj
Posts: 646
Joined: 2009-12-25 17:21

Re: Tips: Common CLI commands for beginners

#12 Post by dotlj »

Very nice, thanks for this.

How about

mail
apt update
apt install
apt-cache search (or aptitude search which includes more information, such as if installed or not)
grep pattern [file...]
wget or curl URL

and so on.

awstutor
Posts: 2
Joined: 2018-10-29 16:32
Location: Jaipur

Re: Tips: Common CLI commands for beginners

#13 Post by awstutor »

Nice post on command line cli

Post Reply