Hugo Future Imperfect Slim

Shashi Shetty

Opinions Are My Own.

Linux Basic commands

List of basic Linux commands.

Shashi Shetty

7-Minute Read

SUSE Linux

This article covers the pointers for setting up the Linux test VM on the home computer and basic Linux commands and their usage.

Pointers for settings up the SUSE Linux in your home system are

  • Use existing Hyper V feature on your Windows 10 system rather than a third party tool like virtual box / vmware player.

  • Create an account for the SUSE Linux portal

  • Download the ISO and generate the registration code from the SUSE portal

  • While configuring the Linux guest, use the default virtual switch on hyper v , which would enable internet access on your guest OS

  • To enable SSH, add the rule in the guest suse VM and restart the firewall service

    • sudo firewall-cmd –permanent –add-service=ssh
    • sudo firewall-cmd –reload
Basic Commands
  1. Clear : Clear the terminal , similar to cls of windows operating system

  2. CD - Change Directory

    • ~ : For home directory
    • .. : Parent directory
    • -(hyphen): previous directory
  3. pwd – Prints current absolute path

    linux@localhost:~> pwd
    /home/linux
    linux@localhost:~> cd testfolder/
    linux@localhost:~/testfolder>
    linux@localhost:~/testfolder> cd ~
    linux@localhost:~> pwd
    /home/linux
    linux@localhost:~> cd testfolder/
    linux@localhost:~/testfolder> cd ..
    linux@localhost:~> pwd
    /home/linux
    linux@localhost:~> cd /etc
    linux@localhost:/etc> pwd
    /etc
    linux@localhost:/etc> cd -
    /home/linux
       
    
  4. touch - Create an empty file . You can create more than one file by separating the names of files by space.

  5. ls - lists the files and folders in the current directory. “.” refers to the current folder, and “..” refers to the parent folder. Below are some of the common use options for the ls command.

    • lt - newest files are displayed first
    • lr - newest files are displayed at the last
    • lh - display the size of files in human-readable format
linux@localhost:~> touch file1

linux@localhost:~> touch 1 2 3

linux@localhost:~> ls
1  2  3  bin  file1  file2  file-update  public_html  testfile  testfolder

linux@localhost:~> ls -lt
total 4
-rw-r--r-- 1 linux users  0 Mar 31 18:39 1
-rw-r--r-- 1 linux users  0 Mar 31 18:39 2
-rw-r--r-- 1 linux users  0 Mar 31 18:39 3
-rw-r--r-- 1 linux users  0 Mar 31 18:39 file1
drwxr-xr-x 2 linux users  6 Mar 31 18:36 testfolder
drwxr-xr-x 2 linux users  6 Mar 31 18:01 bin
-rw-r--r-- 1 linux users  6 Mar 31 17:28 file2
-rw-r--r-- 1 linux users  0 Mar 31 17:27 file-update
-rw-r--r-- 1 root  root   0 Mar 31 15:34 testfile
drwxr-xr-x 2 linux users 24 Mar 30 23:30 public_html

linux@localhost:/var/log> ls -lhr
total 1.4M
-rw-r----- 1 root   root   306K Mar 30 18:10 zypper.log
drwxr-x--- 1 root   root     14 Mar  9 10:36 zypp
drwx------ 1 root   root    504 Mar 30 23:30 YaST2
-rw-rw-r-- 1 root   utmp    21K Mar 31 15:20 wtmp
-rw-r----- 1 root   root    21K Mar 31 15:08 warn
-rw------- 1 root   root   4.0M Mar 31 15:57 tallylog
-rw-r----- 1 root   root    14K Mar 31 18:01 snapper.log
drwxr-x--- 1 root   root      0 Feb 27 01:19 samba
-rw------- 1 root   root   4.1K Mar 30 23:30 pbl.log
-rw-r----- 1 root   root      0 Mar 30 23:29 NetworkManager
-rw-r----- 1 root   root   793K Mar 31 18:40 messages
-rw-r----- 1 root   root      0 Mar 30 23:29 mail.warn
-rw-r----- 1 root   root   2.2K Mar 31 15:09 mail.info
-rw-r----- 1 root   root      0 Mar 30 23:29 mail.err
-rw-r----- 1 root   root   2.2K Mar 31 15:09 mail
-rw-rw-r-- 1 root   utmp   286K Mar 31 15:57 lastlog
drwx------ 1 root   root      0 Nov  9 22:03 krb5
-rw-r----- 1 root   root      0 Mar 30 18:02 firewalld
-rw-r----- 1 root   root      0 Mar 30 23:29 firewall
lrwxrwxrwx 1 root   root     10 Mar 30 23:29 dump -> /var/crash
drwxr-xr-x 1 lp     lp        0 Jan 11 23:05 cups
drwxr-x--- 1 chrony chrony    0 Oct  9 11:29 chrony
-rw-rw---- 1 root   utmp   1.5K Mar 30 22:43 btmp
-rw-r--r-- 1 root   root    36K Mar 30 22:44 boot.omsg
-rw-r--r-- 1 root   root    35K Mar 31 15:08 boot.msg
-rw------- 1 root   root    77K Mar 31 15:09 boot.log
drwx------ 1 root   root     18 Mar 30 18:02 audit
drwxr-xr-x 1 root   root      0 Jun 22  2020 apparmor
-rw-r--r-- 1 root   root   9.3K Mar 30 23:30 alternatives.log
-rw-r----- 1 root   root      0 Mar 30 23:29 acpid

  1. chown - Change owner of the file or folder

  2. chmod - Change permission of a file or folder. First three bits refers to user, next 3 are for group and last 3 are for others. You can even use numbers to change permission

    • read = 4

    • write = 2

    • execute = 1

For example if you give 7 , all read ,write and execute permissions are assigned.

localhost:/home/linux/testfolder # ll
total 0
-rw-r--r-- 1 root root 0 Mar 31 18:47 file1
-rw-r--r-- 1 root root 0 Mar 31 18:47 file2

localhost:/home/linux/testfolder # chmod u+x file1
localhost:/home/linux/testfolder # ll
total 0
-rwxr--r-- 1 root root 0 Mar 31 18:47 file1
-rw-r--r-- 1 root root 0 Mar 31 18:47 file2

localhost:/home/linux/testfolder # chown linux file1
localhost:/home/linux/testfolder # ll
total 0
-rwxr--r-- 1 linux root 0 Mar 31 18:47 file1
-rw-r--r-- 1 root  root 0 Mar 31 18:47 file2

localhost:/home/linux/testfolder # chmod 765 file2
localhost:/home/linux/testfolder # ll
total 0
-rwxr--r-- 1 linux root 0 Mar 31 18:47 file1
-rwxrw-r-x 1 root  root 0 Mar 31 18:47 file2

  1. find - finds the file/s in the path mentioned .First example is finding the file with name file1 in /(root). In second example find will only look in /home/linux directory

    localhost:/home/linux/testfolder # find / -name file1
    /home/linux/testfolder/file1
    /home/linux/file1
       
    localhost:/home/linux/testfolder # find /home/linux -name file2
    /home/linux/file2
    /home/linux/testfolder/file2
         
    
  2. cp - copy or replace files in the current directory

    • i : used for reconfirmation
  3. rm - remove the files are folders. Like cp commond “i” is used for reconfirmation.

  4. rmdir - Removes an empty directory.

  5. mkdir - Cretes a new directory.

  6. mv - rename / move files .

localhost:/home/linux/testfolder # cp file1 file2
localhost:/home/linux/testfolder # ll
total 8
-rwxr--r-- 1 linux root 14 Mar 31 18:59 file1
-rwxrw-r-x 1 root  root 14 Mar 31 19:00 file2

localhost:/home/linux/testfolder # rm file2
localhost:/home/linux/testfolder # ll
total 4
-rwxr--r-- 1 linux root 14 Mar 31 18:59 file1

localhost:/home/linux/testfolder # touch file2
localhost:/home/linux/testfolder # ll
total 4
-rwxr--r-- 1 linux root 14 Mar 31 18:59 file1
-rw-r--r-- 1 root  root  0 Mar 31 19:00 file2

localhost:/home/linux/testfolder # cp -i file1 file2
cp: overwrite 'file2'? n
localhost:/home/linux/testfolder # ll
total 4
-rwxr--r-- 1 linux root 14 Mar 31 18:59 file1
-rw-r--r-- 1 root  root  0 Mar 31 19:00 file2

localhost:/home/linux/testfolder # cp -i file1 file2
cp: overwrite 'file2'? y
localhost:/home/linux/testfolder # ll
total 8
-rwxr--r-- 1 linux root 14 Mar 31 18:59 file1
-rw-r--r-- 1 root  root 14 Mar 31 19:00 file2

localhost:/home/linux # find file*
file-update
file1
file2
localhost:/home/linux # mv file* testfolder2
localhost:/home/linux # cd testfolder2
localhost:/home/linux/testfolder2 # ll
total 4
-rw-r--r-- 1 linux users 0 Mar 31 17:27 file-update
-rw-r--r-- 1 linux users 0 Mar 31 18:39 file1
-rw-r--r-- 1 linux users 6 Mar 31 17:28 file2

localhost:/home/linux # rmdir testfolder2
rmdir: failed to remove 'testfolder2': Directory not empty

localhost:/home/linux # rmdir testfolder3
localhost:/home/linux # find testfo*
testfolder2
testfolder2/file-update
testfolder2/file1
testfolder2/file2

  1. passwd - Change the password of current logged in user . Only root can change the password of other users. password username is used to change password for user “username”

  2. head - display first 10 lines of a file; “-” is used to filter the number of lines to be displayed .

  3. tail - display last 10 lines of a file

localhost:/home/linux/testfolder2 # head /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:478:478:Chrony Daemon:/var/lib/chrony:/bin/false
daemon:x:2:2:Daemon:/sbin:/sbin/nologin
lp:x:497:487:Printing daemon:/var/spool/lpd:/sbin/nologin
mail:x:498:498:Mailer daemon:/var/spool/clientmqueue:/sbin/nologin
man:x:13:62:Manual pages viewer:/var/lib/empty:/sbin/nologin
messagebus:x:499:499:User for D-Bus:/run/dbus:/usr/bin/false
nobody:x:65534:65534:nobody:/var/lib/nobody:/bin/bash
nscd:x:479:479:User for nscd:/run/nscd:/sbin/nologin
polkitd:x:496:484:User for polkitd:/var/lib/polkit:/sbin/nologin

localhost:/home/linux/testfolder2 # head  -2 /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:478:478:Chrony Daemon:/var/lib/chrony:/bin/false

localhost:/home/linux/testfolder2 # tail  -2 /etc/passwd
linux:x:1000:100:linux:/home/linux:/bin/bash
testuser:x:1001:100::/home/testuser:/bin/bash

localhost:/home/linux/testfolder2 # tail  /etc/passwd
root:x:0:0:root:/root:/bin/bash
rpc:x:476:65534:user for rpcbind:/var/lib/empty:/sbin/nologin
sshd:x:477:477:SSH daemon:/var/lib/sshd:/bin/false
statd:x:475:65533:NFS statd daemon:/var/lib/nfs:/sbin/nologin
systemd-coredump:x:481:481:systemd Core Dumper:/:/sbin/nologin
systemd-network:x:482:482:systemd Network Management:/:/sbin/nologin
systemd-timesync:x:480:480:systemd Time Synchronization:/:/sbin/nologin
vnc:x:474:476:user for VNC:/var/lib/empty:/sbin/nologin
linux:x:1000:100:linux:/home/linux:/bin/bash
testuser:x:1001:100::/home/testuser:/bin/bash

  1. more / less - Display content of a file in pages; one everyday use case is reading man pages or log files. less command is comparably faster than more, as more command loads the entire file to memory where as less will load the files partially . Enter key is used to navigate to next line and space bar is for next page .

  2. history - Prints the commands history . “!!” - runs the previous command . “!2” runs the second command in the history. “echo $HISTFILE” prints the location of history file for root user .

  3. tab key - Auto fills the command/file name. Double tab is to disapply all the files matching the criteria.

Say Something

Comments

Nothing yet.

Recent Posts

Categories

About

Dependable and goal-oriented IT infrastructure engineer with 12 years of experience in designing and delivering infrastructure projects.