Skip to main content

1. Essential Commands - 25%

  • [Log into local & remote graphical and text mode consoles]
  • [Search for files]
  • [Evaluate and compare the basic file system features and options]
  • [Compare and manipulate file content]
  • [Use input-output redirection]
  • [Analyze text using basic regular expressions]
  • [Archive, backup, compress, unpack, and uncompress files]
  • [Create, delete, copy, and move files and directories]
  • [Create and manage hard and soft links]
  • [List, set, and change standard file permissions]
  • [Read, and use system documentation]
  • [Manage access to the root account]

Log into local & remote graphical and text mode consoles

Introduction Terminology

  1. a terminal is in Unix a textual input/output handling device, but the term is more often used for pseudo-terminals (pts) that allows us to access and use the shell (e.g. terminal emulators Console on KDE)
  2. a console was originally a physical terminal device connected with Linux system on serial port via serial cable physically, but now by virtual console is meant an app which simulates a physical terminal (on Unix-like systems, such as Linux and FreeBSD, the console appears as several terminals (ttys) accessed via spacial keys combinations)
  3. a shell is a command line interpreter (e.g. bash) invoked when a user logs in, whose primary purpose is to start other programs.

Log-In

  1. To log into local environment you must provide, when prompted, userID and password for both graphical and text mode
  2. To login into a remote text environment you can use command ssh
  3. To login into a remote graphical environment you can use command ssh -X
[root@localhost ~]# w
23:41:16 up 2 min, 2 users, load average: 0.02, 0.02, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 23:40 60.00s 0.01s 0.01s -bash
root pts/0 192.168.0.34 23:41 1.00s 0.02s 0.00s w

First column shows which user is logged into system and the second one to which terminal.

  • For Virtual Console in terminal is showed tty1, tty2 etc.
  • For ssh remote sessions (pseudo-terminal) in terminal is showed pts/0, pts/1 etc.
  • :0 is for X11 server namely used for graphical login

Search for files

Key Command

# Find files with depth 3 and size above 2 mb
find . -maxdepth 3 -type f -size +2M

# Find files with permission 777 and remove them
find /home/user -perm 777 -exec rm '{}' +

# Find files based on how many times they have been accessed (-atime n) or modified (-mtime n) (with n = n*24 hours ago):
find /etc -iname "*.conf" -mtime -180 –print

# To combine two conditions:
`find . \( -name name1 -o -name name2 \)`

# To negate a condition:
`find . \! -user owner`

# To search for a filename ignoring the case:
`find . -iname name`

# Find all files with at least (`-` sign before `g` in this example) permission write for group:
`find . -perm -g=w`

# Audit a system to find files with root SUID/SGID:
`sudo find / -user root \( -perm 4000 -o -perm 2000 \) -print`

# Remove a file by inode:
`find . -maxdepth 1 -type f -inum 7404301 -delete`

# Combine find and grep:
`find . -name "*.md" -exec grep -Hni --color=always inode {} \;`

Alternatively, you can use the `locate` command, which searches for a given pattern through a database file that is generated by the `updatedb` command. The found results are displayed on the screen, one per line.

# For example to search for a file named *.bashrc* you would type:
`locate .bashrc`

File Globbing

File globbing is a feature provided by the UNIX/Linux shell to represent multiple filenames by using special characters called wildcards with a single file name. Long ago, in UNIX V6, there was a program /etc/glob that would expand wildcard patterns. Soon afterward this became a shell built-in.

A wildcard is essentially a symbol which may be used to substitute for one or more characters. Therefore, we can use wildcards for generating the appropriate combination of file names as per our requirement.


# Use `*` to mean "every character":
ls -l a*

# Use `?` for a single character:
ls -l a?

# Use square brackets to declare a set of characters:
ls -l a[ab]

# Wildcards can be combined:
ls -l a[a-c]*

# Use curly braces to consider any listed element:
mkdir /etc/{public,private,protected}

# `!` is used to exclude characters from the list that is specified within the square brackets:
ls /lib[!x]*