Cheatography
https://cheatography.com
I'm starting a new job and need to remeber the basics :)
Good sources: https://ss64.com/bash/
https://ubuntu.com/server/docs/package-management
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Need help?
man commandname |
Open the help manual |
apropos keyword |
Searches the keyword inside the help manual |
apropos -a keyword |
Searches for multiple keywords inside the help manual |
commandname --help |
Displays help for the command |
whatis commandname |
One line description of a command |
linuxconf |
Linux configuration |
aspell |
Spell checker |
alias |
To create simple commands |
* Alias example: alias armas ='grep -inT armas Um.txt' --> This defines the command armas to execute the grep command.
* Typing only alias will display the already created commands
Wildcards: (set of characters of arbitrary lenghts); ? (any character); [numbers] (range of characters)
Basic commands
whoami |
To learn your username |
clear |
Clears the screen |
exit |
Exits the terminal |
echo "randomwords" |
Returns what you wrote |
expr number + number |
To perform basic math operations |
date |
Dipslays the date and time of the system |
nano |
Opens nano, the linux text editor |
sqlite3 |
Example of a vesion of sql to use from linux |
soofice |
See files on Libreoffice |
gedit |
Opens text/code editor Gedit |
gedit filename |
Opens the file on Gedit |
cal |
Displays the calender and easter date |
seq |
Prints a numeral sequence |
Permissions
ls -l |
Displays permissions to filesand directories |
ls -la |
Displays permissions to files and directories, including hidden files |
chmod |
Change permissions to files and directories |
sudo |
Temporarily grants elevated permissions |
sudo useradd |
Adds a user to the system |
sudo useradd -g groupname username |
Sets the user's default group |
sudo userass -G group(s)name username |
Adds the user to additional groups |
sudo usermod |
Modifies existing user accounts |
sudo usermod -g |
Changes thhe primary group |
sudo usermo -G |
Changes the secondary group |
sudo usermode -d path username |
Changes the user's home directory |
sudo usermode -l |
Changes the user login name |
sudo usermod -L |
Locks the account |
sudo userdel |
Deletes user |
sudo chown user/groupname file |
Commands changes to the ownership of a file or directory |
Permissions in Linux look like drwxrwxrwx. 1st char is a d (for directory) or - (for regular files). The 3 sets refer to user-group-other.The options for characters are: u (indicats changes will be made to user permissions); g (indicates changes will be made to the group permissions), o (indicates changes will be made to other permissions); + (adds permissions to them); - (removes permissions from them); = (assigns permissions to them)
|
|
Directories & Files
tree |
Lists the directory conten on a tree format |
pwd |
Prints the current working directory path |
ls |
Displays the names of the directories and files in the current directory |
ls -a |
Displays hidden files |
cd directoryname |
Changes directory |
cd / |
Back to the root directory |
cd ~ |
Changes to the home directory |
cd .. |
Changes to the preceding directory |
mkdir newdirectoryname |
Create new directories |
touch |
Creates a new empty file |
rmdir direcotyname |
Delete directories |
rmdir -r |
Deletes the directory and files |
rm filename |
Deletes a file |
cp [options] origin destiny |
Copie files and directories |
mv file/directoryname /path |
Moves directories and files to a new location. Can also be used to rename files. |
tar -xf filename |
Extracts files |
stat filename |
Displays info about an file |
stat -f |
Displays info about the system file (not the file) |
find filename |
To find a file |
- Home directory: the one in which the session is started after login.
- Working directory: the one being used at the moment.
-Root directory: mother directory, first of the tree.
* " " are needed to have spaces on the directory name
*rmdir only works in empty directories
*hidden files will have an . (dot) at the beggining
* stat can be used with multiple files (stat filename filename)
Processes
top |
Shows the executing processes on Linux |
ps |
Shows the active exeuting processes on the machine |
ps -e |
Lists all the processes in order |
ps -f |
Shows the same as ps but in a table |
ps -e-f |
Shows the processes in order, on a table |
ps tree |
Shows the processes in tree |
kill |
Ends the process |
kill -9 |
Is used when kill doesn't work |
kill -1 |
Restarts the process |
* kill -9 and kill -1 can be combined (kill -9-1)
Networks
ping |
Verify if an server is available |
traceroute |
Shows the network route |
nslookup |
Lets you find info about the computer in the network through DNS |
telnet |
Log in securely on a remote computer |
ssh -X |
Log in securely on a remote computer |
Xfce4-session |
Start an graphical session on a remote computer |
exit |
Leave the remote session |
quit |
Leave the remote session |
who |
Shows who has an active session on this machine |
who -w |
Know some more info |
finger |
Shows info about an user |
write username |
Send messages to other users |
talk |
Also used to communciate with other users. In this case, thy msut accept the connection with the same command |
mesg n |
Indicates that I don't want to receive more messages |
mesg y |
Indicates that I'm available |
at |
Schedules the execution of commands on the computer |
scp |
Securely copie files between different machines |
- ping -c 4 apps .fe.up.pt
- nslookup moodle.up.pt or nslookup 193.137.35.211
- telnet towel.clinkenlights.nl.
-ssh -X gnomo.fe.up-pt or ssh -X mccarthy.fe.up.pt
- at 11:15 commandstobeexecuted ctrl+d
-scp user@mccarthy.fe.up.pt:/usr/SCCOM/ola.txt copiado.txt
*when using write, use ctrl+c to send the message or use echo mensagem | write username
|
|
Reading files content
cat filename |
Concatenate and display the content of files |
tac |
Like cat but in reverse |
grep filename |
Returns all lines of a file that contain a specified string |
head filename |
Dispalys the first 10 lines of the file |
head -number |
Displays the n first lines |
tail filename |
Displays the last 10 lines |
tail -number filename |
Displays the last n number of lines |
less |
Displays the content of a file one page at a time |
more filename |
Displays the file |
wc |
Counts characters, words and lines |
wc -c |
Counts bytes |
wc -m |
Counts characters |
wc -w |
Counts words |
nl |
counts the number of lines |
nl -a |
numbers |
sort |
reorganizes the file by lines, so that they are ordered by number and alphabeticaly |
sort -r |
like sort but in reverse |
grep -n |
Prints all lines according to the condition and numerates them |
grep -t |
All the lines will start on the same place |
grep -i |
Looks for the condition, ignoring the letter capitalization |
grep -w |
searches only for the complete word and not for words that contain part of the chosen word |
Joining commands
There are several ways to combine commands on a single line.
Running commands one after the other: ; or && or ||.
&& If the command that preeceds && completes sccessfully, the following is run.
|| If the command that precedes || fails, the following runs.
Run more than one command concurrently (the output from the first command is piped to the next as the first command is runnign): | or a filter with a |
----------------------------------------------
Using ; : cd mydir ; ls
Using && : command && command
Using || : command || command
Using | : history | grep "cp" (displays all the cp commands that are recorded among the 16 most recently recorded command in history file). ls -l | grep "Jan" (displays the files that were last changed in January). ps -e | grep cc | wc -l (lists all o the processes active in the system and pipes the output to grep, which searches for every instace of the string cc. The output of the grep is then piped to wc, which counts every line in which the string cc occurs and sends the number of lines to standard output).
---------------------------------------------
> : redirects the output of a command to an file (the result of the command will appear on the file and not on the shell. When there's content on the file, it will repace it. When there's no file it will create a new one).
>>> : adds to the file |
Administration
apt |
Search for and install software packages |
apt-get |
Search for and install software packages |
apt remove |
Removes a package |
apt upgrade |
updats the whole system |
apt update |
Upgrades the repository |
- It might be necessary to use sudo to use apt
|