User Tools

Site Tools


Action disabled: media
linux:commands

Basic commands

System informations

To know name and version of one's Linux distribution:

cat /etc/lsb-release

To get kernel (Architecture) and processor architecture (CPU op-mode(s)):

lscpu

To view free and used memory:

free

To view free and used disk space:

df

To view a detailed description of the system's hardware components:

sudo dmidecode

Info: to find out the maximum ram capacity of the computer, refer at type 16 of dmidecode output, for instance:

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 Number of Devices is the number of slots.

Switch among directories

To come back from dir/sub-dir to the parent directory dir:

cd ..

To go to any directory:

cd /absolute/path/folder

Visualize content of directory

To visualize the content of a directory:

ls

To visualize hidden files as well:

ls -a

To visualize a detail list of all files (add the option -a to include also the hidden files):

ls -l

with the following output:

type of file permissions hard links owner group size in bytes date last edit name
d folder
- file
owner group other

Create directory

To create a directory with sub-directory:

mkdir folder/sub-folder

Rename directory

To rename a directory:

mv old-name/ new-name/

this will delete the origin folder.

Copy directory

To copy a directory:

cp -r /absolute/path/from /absolute/path/to

this will retain the origin directory.

Delete empty directory

To delete an empty directory:

rmdir folder

Delete non empty directory

To delete a non empty directory:

rm -r folder

Create file

To create a file:

touch file.txt

Rename file

To rename a file:

mv old-file.txt new-file.txt

this will delete the origin file.

Copy file

To copy a file:

cp /aboslute/path/from.txt /absolute/path/to.txt

this will retain the origin file.

Delete file

To delete a file:

rm file.txt

To create a symbolic link (option -s), which points to a file or a directory:

ln -s /path/origin /path/destination

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't exist.

Change permissions

The general syntax to change the permissions for a file is:

chmod <options> <people><operator><permission> <file|folder>

where:

<people> <operator> <permission>
u users + add
- remove
= remove previously and set new
r read
w write
x execute
g group
o others

For instance:

chmod ugo=rwx file.py

owner, group and others: read, write and execute

chmod u=rwx file.py

owner: reads, writes and executes (previously permissions for group and others are removed)

chmod u=xw,g=r,o=rw file.py

owner: writes and reads; group: reads; others: reads and writes (for all, previously permissions are replaced with the new ones)

chmod u+r,g-r,o=x file.py

owner: added read permission; group: removed read permission; others: executes

chmod -R o=rw folder file.py

others: reads and writes (permission applied recursively at directory and file)

Find string

To find a string:

grep -ilr 'string to find' *

where:

options
-i case insensitivity
-l list results printing only name files
-r recursive search

Tip: wrap the string in superscripts only if it contains blank spaces.

To save the output in a text file:

grep -ril 'string to find' * > /absolute/path/output.txt

To find a string at the start of a line:

grep -ril '^string to find' /absolute/path

To find a string at the end of a line:

grep -ril 'string to find$' /absolute/path

Find file

To find a file in a directory hierarchy:

find /directory file.txt

Tip: use sudo to search in directories where only the superuser has access.

Processes in execution

To know which processes are in execution:

top

To stop a process:

kill <PID>

where <PID> is the process's ID read from the output table of the command top.

List of logged in users

To list the history of logged in users: <code bash> last </last>

linux/commands.txt · Last modified: 2023/12/03 11:10 by tormec