Simple commands (BASH)
At first, the easiest part, but not less important than other commands.
Files and directories management
command | utility | example |
---|---|---|
vim | open programmer's text editor | vim <filename> |
ls | list files and directories in the current directory | ls [route] |
ls-l | list files adding details like permissions,group,owner etc | ls -l |
cd | change to a specific directory | cd <directory> |
mkdir | create a new directory | mkdir <directoryname> |
rmdir | delete an empty directory | rmdir <directoryname> |
rm -r | remove a directory and its content | rm -r <directoryname> |
rm | remove a file | rm <filename> |
cp | copy a file from origin to a destination | cp <originroute> <destinationroute> |
mv | move or rename files or directories | mv <origin> <destination> |
filtering files
command | utility | example |
---|---|---|
grep | search in a file, the the specified character on the command | grep "error" <filename> |
grep -i | -i means to search to make out uppercase letters for lowercase letters | grep -i "error" <filename> |
grep -n | -n means to show the line number of the specified search | grep -n "denied" <filename> |
grep -r | -v means to executate the same action but in a directory | grep -r "*.txt" <directoryname> |
find | find works alike grep but is designed to search directories also | find <directoryname> -n <filename> |
find -t -f | -t to specify the file type, -f specifies the action to search only files | find <directoryname> -t -f |
find -t -d | -t " ", -d specifies the action to search only directories | find <directoryname> -t -d |
management for compressed files
command | utility | example |
---|---|---|
gzip | compress a file, if the file does not exist create"*.gz" file | gzip <filename> |
gzip -d | -d says to decompress a ".gz" file | gzip -d <filename> |
tar -cvf | make a ".tar" file froma a direcftory | tar -cvf <filename.tar> <directoryname> |
tar -xvf | extract the file content from a ".tar" file | tar -xvf <filename.tar> |
replacing characters
command | utility | example |
---|---|---|
tr 'y' 'n' | replace "y" characters for "n" characters (also could be special characters) | grep -i 'y' | tr "y" "n" |
tr -d 'x' | delete 'x' characters (also could be special characters) | grep "*.zip" | tr -d '.zip' |
filtering and processing data
command | utility | example |
---|---|---|
cut | cut columns for files or data chains | <--- intro |
cut -d -f | -d is to specify the character that separate the information, -f to specify the interval of columns to show | grep -t -f <filename> | cut ' ' -f 1,6 |
sort | like its name, sort the file lines alphabetically | grep -t -f <filename> |sort |
sort -n | -n means to sort filelines in numeric order | grep -t -f <filename> | sort -n |
sort -r | sort the filelines inversely | grep -t -f <filename> | sort -r |
Intermediated commands (BASH)
Commands assigned to users, groups and permissions.
Users
sudo
that command allows to users to execute commandlines as superuser (root).
useradd (create users)
command | utility | example |
---|---|---|
usserad | create a new user as root | sudo useradd alberto |
-m | create a new user within itself directory | sudo useradd -m player |
usermod (modofy user info)
command | utility | example |
---|---|---|
-l | change username | sudo usermod <currentname> <newname> |
-L | lock user's account avoiding user's login | sudo usermod -L <username> |
-U | unlock an account that is already locked | sudo usermod -U <lockeduser> |
-u | changhe user's identifIer (UID) | sudo usermod -u <newUID> <username> |
-g | change user's primary group | sudo usermod -g <group> <username> |
-d | specify directory | sudo usermod -d /home/super |
-m | move directory data to specified route | sudo usermod home/super -m major |
-e | change user's due date | sudo usermod -e <date> <username> |
-aG | add user's to a new group without removing it from the group that is already there | sudo usermod -aG <group> <username> |
userdel (delete user)
command | utility | example |
---|---|---|
userdel | remove a user without deleting this user's files or directories | sudo userdel <username> |
-r | remove a user, the remove user's files and directories | sudo userdel -r <username> |
Groups
sudo
groupadd
command | utility | example |
---|---|---|
groupadd | create a simple group with the specified name | sudo groupadd <groupname> |
-g | create a group with its group identifier (GID) | sudo groupadd <GID> <groupname> |
-c | create a group with attached comment | sudo groupadd "<comment>" <groupname> |
groupdel
command | utility | example |
---|---|---|
groupdel | removes a group but not its users | sudo groupdel <groupname> |
groupmod
command | utility | example |
---|---|---|
groupmod | is used to modify existing users groups | <- intro |
-n | modify to a group its name | sudo groupmod -n <newname> <oldname> |
-g | change group identifier (GID) | sudo groupmod -g <newGID> <groupname> |
-c | add or modify group's comment | sudo groupmod -c "<comment>" <groupname> |
permissions
chmod
Simple
chmod command simple syntax :
- r (read): reading permission
- w (write): writing permission
- x (execution): execution permission
permissions apply to three entities: user (u), group (g), and others (o).
command | utility | example |
---|---|---|
chmod | to change permissions | <-- intro |
u+x | specifies to add (+) user (u) execution (x) permissions for file owner | chmod u+x <filename> |
g-w | specifies to remove (-) owner group (g) writting (w) permissions | chmod g-w <filename> |
o+r | specifies to add (+) other users (o) reading (r) permissions | chmod o+r <filename> |
Octal
chmod command octal syntax are specified with octal characters:
4 Reading
2 Writing
1 Execution
permissions apply to three entities contemplating the number and its position (u g o): user (u), group (g), and others (o).
resource | justification | command |
---|---|---|
7 6 4 | 7 (4+2+1): reading, writing and execution for owner user (first position) 6 (4+2+0): reading and writing for group (second position) 4 (4+0+0): only reading for other users (third position) | chmod 764 <filename> |
6 4 0 | 6 (4+2+0): reading and writing for owner user (first position) 4 (4+0+0): reading for group (second position) 0 (0+0+0): none permission for other users (third position) | chmod 640 <filename> |
7 0 0 | 7 (4+2+1): reading, writing and execution for owner user (first position) 0 (0+0+0): none permission for group (second position) 0 (0+0+0): none permission for other users (third position) | chmod 700 <filename> |
-R | modify permissions of all directories and files on the specified route | chmod -R 700 <wished/directory/route> |