linux:commands
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
linux:commands [2020/03/16 15:15] – [Create link] tormec | linux:commands [2023/12/03 11:09] – [Create link] tormec | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Basic commands ====== | ||
+ | |||
+ | |||
+ | ===== System informations ===== | ||
+ | |||
+ | To know name and version of one's Linux distribution: | ||
+ | <code bash> | ||
+ | cat / | ||
+ | </ | ||
+ | |||
+ | To get kernel ('' | ||
+ | lscpu | ||
+ | </ | ||
+ | |||
+ | To view free and used memory: | ||
+ | <code bash> | ||
+ | free | ||
+ | </ | ||
+ | |||
+ | To view free and used disk space: | ||
+ | <code bash> | ||
+ | df | ||
+ | </ | ||
+ | |||
+ | To view a detailed description of the system' | ||
+ | <code bash> | ||
+ | sudo dmidecode | ||
+ | </ | ||
+ | <WRAP info> | ||
+ | **Info:** to find out the maximum ram capacity of the computer, refer at '' | ||
+ | < | ||
+ | Handle 0x000F, DMI type 16, 15 bytes | ||
+ | Physical Memory Array | ||
+ | Location: System Board Or Motherboard | ||
+ | Use: System Memory | ||
+ | Error Correction Type: None | ||
+ | Maximum Capacity: 4 GB | ||
+ | Error Information Handle: Not Provided | ||
+ | Number Of Devices: 2 | ||
+ | </ | ||
+ | where '' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Switch among directories ===== | ||
+ | |||
+ | To come back from '' | ||
+ | <code bash> | ||
+ | cd .. | ||
+ | </ | ||
+ | |||
+ | To go to any directory: | ||
+ | <code bash> | ||
+ | cd / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Visualize content of directory ===== | ||
+ | |||
+ | To visualize the content of a directory: | ||
+ | <code bash> | ||
+ | ls | ||
+ | </ | ||
+ | |||
+ | To visualize hidden files as well: | ||
+ | <code bash> | ||
+ | ls -a | ||
+ | </ | ||
+ | |||
+ | To visualize a detail list of all files (add the option '' | ||
+ | <code bash> | ||
+ | ls -l | ||
+ | </ | ||
+ | with the following output: | ||
+ | ^ type of file ^ permissions ^ hard links ^ owner ^ group ^ size in bytes ^ date last edit ^ name ^ | ||
+ | | '' | ||
+ | |||
+ | |||
+ | ===== Create directory ===== | ||
+ | |||
+ | To create a directory with sub-directory: | ||
+ | <code bash> | ||
+ | mkdir folder/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Rename directory ===== | ||
+ | |||
+ | To rename a directory: | ||
+ | <code bash> | ||
+ | mv old-name/ new-name/ | ||
+ | </ | ||
+ | this will **delete** the origin folder. | ||
+ | |||
+ | |||
+ | ===== Copy directory ===== | ||
+ | |||
+ | To copy a directory: | ||
+ | <code bash> | ||
+ | cp -r / | ||
+ | </ | ||
+ | this will **retain** the origin directory. | ||
+ | |||
+ | |||
+ | ===== Delete empty directory ===== | ||
+ | |||
+ | To delete an empty directory: | ||
+ | <code bash> | ||
+ | rmdir folder | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Delete non empty directory ===== | ||
+ | |||
+ | To delete a **non** empty directory: | ||
+ | <code bash> | ||
+ | rm -r folder | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Create file ===== | ||
+ | |||
+ | To create a file: | ||
+ | <code bash> | ||
+ | touch file.txt | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Rename file ===== | ||
+ | |||
+ | To rename a file: | ||
+ | <code bash> | ||
+ | mv old-file.txt new-file.txt | ||
+ | </ | ||
+ | this will **delete** the origin file. | ||
+ | |||
+ | |||
+ | ===== Copy file ===== | ||
+ | |||
+ | To copy a file: | ||
+ | <code bash> | ||
+ | cp / | ||
+ | </ | ||
+ | this will **retain** the origin file. | ||
+ | |||
+ | |||
+ | |||
+ | ===== Delete file ===== | ||
+ | |||
+ | To delete a file: | ||
+ | <code bash> | ||
+ | rm file.txt | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Create link ===== | ||
+ | |||
+ | To create a symbolic link (option '' | ||
+ | <code bash> | ||
+ | ln -s / | ||
+ | </ | ||
+ | |||
+ | Note that a symbolic link is just a path so that if the file or the directory is deleted the link will still work but will point to something that doesn' | ||
+ | |||
+ | ===== Change permissions ===== | ||
+ | |||
+ | The general syntax to change the permissions for a file is: | ||
+ | < | ||
+ | chmod < | ||
+ | </ | ||
+ | where: | ||
+ | ^ ''< | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | For instance: | ||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code bash> | ||
+ | chmod ugo=rwx file.py | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP half column> | ||
+ | owner, group and others: read, write and execute | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code bash> | ||
+ | chmod u=rwx file.py | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP half column> | ||
+ | owner: reads, writes and executes (previously permissions for group and others are removed) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code bash> | ||
+ | chmod u=xw, | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP half column> | ||
+ | owner: writes and reads; group: reads; others: reads and writes (for all, previously permissions are replaced with the new ones) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code bash> | ||
+ | chmod u+r,g-r,o=x file.py | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP half column> | ||
+ | owner: added read permission; group: removed read permission; others: executes | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP half column> | ||
+ | <code bash> | ||
+ | chmod -R o=rw folder file.py | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP half column> | ||
+ | others: reads and writes (permission applied recursively at directory and file) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Find string ===== | ||
+ | |||
+ | To find a string: | ||
+ | <code bash> | ||
+ | grep -ilr ' | ||
+ | </ | ||
+ | where: | ||
+ | ^ options ^ ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | <WRAP tip> | ||
+ | **Tip:** wrap the string in superscripts only if it contains blank spaces. | ||
+ | </ | ||
+ | |||
+ | To save the output in a text file: | ||
+ | <code bash> | ||
+ | grep -ril ' | ||
+ | </ | ||
+ | |||
+ | To find a string at the start of a line: | ||
+ | <code bash> | ||
+ | grep -ril ' | ||
+ | </ | ||
+ | |||
+ | To find a string at the end of a line: | ||
+ | <code bash> | ||
+ | grep -ril ' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Find file ===== | ||
+ | |||
+ | To find a file in a directory hierarchy: | ||
+ | |||
+ | <code bash> | ||
+ | find /directory file.txt | ||
+ | </ | ||
+ | |||
+ | <WRAP tip> | ||
+ | **Tip:** use '' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Processes in execution ===== | ||
+ | |||
+ | To know which processes are in execution: | ||
+ | <code bash> | ||
+ | top | ||
+ | </ | ||
+ | |||
+ | To stop a process: | ||
+ | <code bash> | ||
+ | kill <PID> | ||
+ | </ | ||
+ | where ''< | ||
+ | |||
+ | |||
+ | ===== List of logged in users ===== | ||
+ | |||
+ | To list the history of logged in users: | ||
+ | <code bash> | ||
+ | last | ||
+ | </ | ||
+ | |||
linux/commands.txt · Last modified: 2023/12/03 11:10 by tormec