Quick reference of linux essentials and utilities to the beginner linux user. These notes were written quite a whilte ago, so some inaccurasies might be expected.
Is a Linux filesystem standard, presented in the following screen
Each file in Linux has Three(3) modes of access
- Owner (section 2)
- Group (section 3)
- Others (section 4)
Each "mode of access" or user can possess a combination of Three(3) available permissions
- Read - R - 4 (octal representation of permission)
- Write - W - 2
- Execute - X - 1
The Octal representation can benefit us when using tools like 'chmod' to modify the permissions
- Section 1 reveals what type the object is:
- d : directory
- : regular file
- l : soft link
- Section 2,3,4 are detailed permissions for the respective user
- Section 5 details any alternative access methods
- '-' : No other method
- '.' : SELinux
- '+' : FACLs
- '+' : Any combination of methods
- Section 6,7 are names of the Owner and Group respectively
The manuals also document and present the type of "command" or tool as the following table displays:
- 1 - User Commands
- 2 - Programming interfaces for kernel system calls
- 3 - Programming interfaces to the C library
- 4 - Special files such as device nodes and drivers
- 5 - File formats
- 6 - Games and amusements such as screen-savers
- 7 - Miscellaneous
- 8 - System administration commands
Can search using keywords with the "-k" flag and also with Regular Expressions, Just apply it inline
man -k passwd
chgpasswd (8) - update group passwords in batch mode
chpasswd (8) - update passwords in batch mode
gpasswd (1) - administer /etc/group and /etc/gshadow
grub-mkpasswd-pbkdf2 (1) - generate hashed password for GRUB
pam_localuser (8) - require users to be listed in /etc/passwd
passwd (1) - change user password
passwd (1ssl) - compute password hashes
passwd (5) - the password file
update-passwd (8) - safely update /etc/passwd, /etc/shadow and /etc/group
A way to search for a given tool by searching keywords from it's description.
addpart (8) - simple wrapper around the "add partition" ioctl
all-swaps (7) - event signalling that all swap partitions have been activated
cfdisk (8) - display or manipulate disk partition table
cgdisk (8) - Curses-based GUID partition table (GPT) manipulator
delpart (8) - simple wrapper around the "del partition" ioctl
fdisk (8) - manipulate disk partition table
fixparts (8) - MBR partition table repair utility
gdisk (8) - Interactive GUID partition table (GPT) manipulator
growpart (1) - extend a partition in a partition table to fill available space
partprobe (8) - inform the OS of partition table changes
partx (8) - tell the Linux kernel about the presence and numbering of on-disk partitions
resizepart (8) - simple wrapper around the "resize partition" ioctl
sfdisk (8) - partition table manipulator for Linux
sgdisk (8) - Command-line GUID partition table (GPT) manipulator for Linux and Unix
- find# Find all the files whose name is tecmint.txt in a current working directory.find /home -name tecmint.txt# Find Files Using Name and Ignoring Casefind /home -iname tecmint.txt# Find Directories Using Namefind / -type d -name Tecmint# Find Files With 777 Permissionsfind . -type f -perm 0777 -print
- ss (viewing)
Kali linux is a Debian distribution that utilizes the Advanced package tool (APT) software to provide a package management software services in kali linux.
Two main application exists as an interface to managing software packages:
- aptapt is a simplified and user-friendly version of apt-getCommon command:list - list packages based on package namessearch - search in package descriptionsshow - show package detailsinstall - install packagesreinstall - reinstall packagesremove - remove packagesautoremove - Remove automatically all unused packagesupdate - update list of available packagesupgrade - upgrade the system by installing/upgrading packagesfull-upgrade - upgrade the system by removing/installing/upgrading packagesedit-sources - edit the source information file
apt installs software package and fulfils those software's dependencies recursively
dpkg is a core tool used to install packages on linux directly or indirectly through "apt".
dpkg those not resolve and install dependencies recursively according to the software's needs so that's something to take into account
- dpkg can also install packages offline from a .deb file by using the -i or —install flag
View environment variable:
- env Add environment variable:
The are 3 streams of information in linux CLI
- STDIN(0) - program input
- STDOUT(1) - program output / result output
- STRERR(2) - error messages stream
the information present in those streams can be redirected in multiple ways:
- redirect information to be written as a file ( >, >> )
- redirect information and input to a program ( | )
- reverse redirection, etc. ( < )
command: cat some_file.txt
some_file.txt # STDIN 'some_file.txt'
"this is the text of 'some_file.txt'" # STDOUT
"file doesn't exist" #STDERR
### Redirection and piping ###
cat some_file.txt > new_file.txt
"appended text" >> new_file.txt
cat some_file.txt | grep -i
grep 'something' < file_to_grep.txt
Bash have a history file named ".bash_history" that can be displayed by the command "history"
Shortened CLI command execution:
- ! - will execute the command in the specified numerical row in the history file
- !! - will execute the last executed command
- CTRL + R - reverse-i-search will prompt a search bar for search commands in the history file and then executing them.
Common and powerful tools are:
- grep - searches for regex occurrences in the files
- awk - like cut but more complex and verbose
- cut - used to cut text from a line according to specific parameters
- sed - edits text from a stream
There are many text editor, some more capable and complicated than others
dd # Delete current lineyy # Copy current linep # Pase clipboard contentcom
- Good to know flags
- insert - to begin typing
- ~ - to enter command mode
- :q! - Quit without saving changes
- :w - Write file to disk
- :wq! - Save changes and quit
- comm - creates output of 3 columns in this order [ A_UNIQUE_LINES(1), B_UNIQUE_LINES(2), AB_SIMILLAR_LINES]
-n 12 (column 1 and 2)
- -n <column_num> - a flag to control visibility of columns
- diff - ' - ' precedes occurrence in 1st file where not in 2nd file ' + ' precedes occurrence in 2nd file where not in 1st fileNote: When using the -c format flag, similar lines will be present in the output, when using the -u format flag, only different lines will be printed
- vimdiff - compares two files against each other visually with color coding
Processes can work in the "background" or in the "foreground", the difference between the two is the terminal focus position.
Also, there is a mechanism that combines multiple processes that work together as a "job" which can also be managed.
- bg - sending a process / job to the background allowing you to continue working in the terminal
- Another easy way to background a process is by appending "&" to the end of the execution command.
- fg - Sending a process or a job to foreground
- jobs - shows the current active jobs with an ID number for each, you can use bg and fg in combination with that number.
- ps - shows active process on the machine
- -ef - select all process with full format listing
- -C - searches for the process execution command
- kill - kills a process by getting a PID
"tail" display the last lines of a given text file
"-n" enables you to choose number of lines to display
"watch" is a utility that executes a command in a given (or default) time interval
"-n" will determine the interval
download webpages and files.
-O to choose a new name for the downloaded file
download webpages and files.
A download accelerator, downs a file in multiple streams
~/.bashrc is the bash configuration file.
a utility to export environment variable for global terminal usage
export HISTTIMEFORMAT='%F %T '
A utility for creating aliases
alias .. ="cd .."