Site icon LinuxCommands.site

Linux common commands tutorial and use examples

Linux command tutorials like you share common Linux commands, syntax and use cases, and will not list the options and parameters of each command in detail.

Linux Commands Tutorial

1. Linux common directory command list

linux cd command

   cd dir

In the following example we will switch to the previous directory.

   cd - : switch to the previous directory

In the following example we will switch to the user root directory.


   cd (~) : switch to the user root directory

linux pwd command

   pwd

linux ls command

   ls dir
   ls -a DIR : list all directories and files, including. * files

linux mkdir command

   mkdir dir
   mkdir -p /path/dir : create multilevel directories

linux rmdir command

   rmdir [-p] directory

2. Linux file operations commands

linux touch command

   touch file

linux vim command

   vim/vi file

linux rm command

   rm file
   rm -rf / 
   rm -rf *
   rm -rf ~
      -r: indicates the following together; 
      -f: means no user confirmation required;

linux file command

   file file

linux mv command

linux ln/link command

linux unlink command

linux lsof command

3. Linux file permissions commands

linux chown command

linux chmod command

   chmod +x file : add execution permissions for all users to existing permissions
   chmod 777 file : give file owners read, write, and execute permissions

linux chgrp command

4. Linux file content view commands

linux grep command

linux more command

linux less command

linux cat command

linux head command

linux tail command

In the following example we will get the last 10 lines of the file file.log and the new content as they get appended to the file.

    tail -f file.log
    -f: tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input

5. Linux text processing commands

linux vim/vi command

linux awk command

linux sed command

linux sort command

linux tr command

        tr [-Ccsu] string1 string2
        tr [-Ccu] -d string1

6. Linux file query related commands

linux find command

linux locate command

linux ls|grep command

7. Linux file copy related commands

linux cp command

linux scp command

linux syncs command

   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
   rsync [OPTION]... [USER@]HOST:SRC [DEST]

8. Command related commands

linux which command

linux whereis command

linux man command

linux help command

linux alias command

linux sudo command

linux history command

9. System related commands


reboot/halt
    syntax: 
        halt [-lnqu]
        reboot [-lnq]
    explain: stopping and restarting the system

init 0-6
    syntax: init [0 - 6]
    explain: 0 is shutdown, 1 single user mode (can change root password), 2 multi-user mode (cannot use network), 3 full multi-user, 4 graphics, 5 security mode, 6 restart

shutdown
    syntax: shutdown time
    explain: close down the system at a given time

10. Process related commands

linux ps command

In the following example we will list the running system processes.

   ps -ef 
       : list current system processes

In the following example query whether the system is running the process.

   ps -ef | grep xxx
       : whether the query process is executing

linux kill command

     kill pid
     kill -signal_number pid
    kill -9 pid : forced killing process

linux killall command


    syntax: killall procname
    explain: kill processes by name

linux top command


   top option

11. Network/port related commands


netstat
    syntax: netstat option
    explain: show network status
    case: 
        netstat -anp | grep 80
            :view port 80 information

nc
    syntax: nc option
    explain: arbitrary TCP and UDP connections and listens

12. Disk related commands


df
    syntax: df [-b | -h | -H | -k | -m | -g | -P] [-ailn] [-t] [-T type] [file | filesystem ...]
    explain: display free disk space
    case: 
        df -h : view disk usage

du
    syntax: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] [-I mask] [file ...]
    explain: display disk usage statistics
    case: 
        du -sh *
            :display current directory file size

mount
    syntax: mount [option] device dir
    explain: mount file systems

umount
    syntax: umount [option] special | node
    explain: dismount a filesystem

fdisk
    syntax: fdisk [option] device
    explain: DOS partition maintenance program

13. User management related commands


su
    syntax: su user
    explain: switch user

useradd
    syntax: useradd user
    explain: add user

userdel
    syntax: userdel user
    explain: delete user

groupadd
    syntax: groupadd group
    explain: add group

groupdel
    syntax: groupdel group
    explain: delete group

passwd
    syntax: passwd [-i infosystem [-l location]] [-u authname] [user]
    explain: modify a user's password

14. Compression and decompression related commands


gzip/unzip
    syntax: 
        gzip option file
        unzip option file[.zip]
    explain: compression/decompression tool using Lempel-Ziv coding (LZ77)

zcat
    syntax: zcat file
    explain: print compressed file content

tar
    syntax: tar  [options] [patterns]
    explain: manipulate tape archives

bzip2/bunzip2/bzcat
    syntax: 
        bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ...  ]
        bunzip2 [ -fkvsVL ] [ filenames ...  ]
        bzcat [ -s ] [ filenames ...  ]
    explain: a block-sorting file compressor

15. Other Common Commands

linux crontab command


uname
    syntax: uname [-amnprsv]
    explain: print operating system name

date
    syntax: date option
    explain: display or set date and time

service
    syntax: service SERVICE start/stop/restart
    explain: service management

wc
    syntax: wc [-clmw] [file ...]
    explain: word, line, character, and byte count

source
    syntax: source filename or .filename
    explain: make the shell read into the specified shell program file and execute all statements in the file in turn

w
    syntax: w [option]
    explain: display who is logged in and what they are doing

echo
    syntax: echo [option]
    explain: write arguments to the standard output

print
    syntax: print contents
    explain: print contents

printf
    syntax: printf format [arguments ...]
    explain: format printed content
    case: 
        printf "Distance is %5d Miles\n" $d

ssh
    syntax: ssh [option] destination [command]
    explain: OpenSSH SSH client

ulimit
    syntax: ulimit [option]
    explain: view system limit
    case: 
        ulimit -a
            :view current limit
        ulimit -n 65535
            :temporary, effective immediately;modify /etc/security/limits.conf file, permanently effective modifications.

16. Special symbols

redirect

>” symbol, left content overwrite to right file

>>” symbol, the content on the left is appended to the end of the file on the right


    >
     :overwrite write
    >>
     :append write

pipe


    |
     : pipe

Exit mobile version