Estudiant d'SMX 1r a l'INS Castellbisbal

Cheat Sheet about Linux commands

1. File and Directory Navigation

CommandDescriptionExample
pwdDisplays the current working directory.pwd → /home/user/Documents
lsLists files and directories in the current location.ls
ls -lLists files with detailed info (permissions, size, date, owner).ls -l
cd [directory]Changes the current directory.cd /etc
cd ..Moves up one level in the directory structure.cd ..
cd /Goes to the root directory.cd /

2. File Management

CommandDescriptionExample
touch [file]Creates an empty file.touch notes.txt
cp [source] [destination]Copies files or directories.cp file.txt /backup/
mv [source] [destination]Moves or renames files/directories.mv old.txt new.txt
rm [file]Deletes a file.rm temp.txt
rm -r [directory]Deletes a directory and all its contents.rm -r old_folder/

3. Text Manipulation

CommandDescriptionExample
cat [file]Displays the content of a file.cat readme.txt
less [file]Opens a file for paginated viewing (scroll up/down).less /etc/passwd
head [file]Shows the first 10 lines.head log.txt
tail [file]Shows the last 10 lines.tail log.txt
grep "text" [file]Searches for a specific word or phrase inside a file.grep "error" log.txt

4. Permissions and Ownership

CommandDescriptionExample
chmod [permissions] [file]Changes file permissions using numeric or symbolic mode.chmod 755 script.sh
chown [user:group] [file]Changes file owner and group.chown root:root config.txt

5. Process Management

CommandDescriptionExample
psDisplays running processes.ps aux
topReal-time view of system processes and usage.top
kill [PID]Terminates a process by its ID.kill 1234
killall [name]Kills all processes with a given name.killall firefox

6. User and Group Management

CommandDescriptionExample
whoamiDisplays the current logged-in user.whoami
whoLists all users currently connected.who
adduser [user]Creates a new user account.sudo adduser alice
deluser [user]Deletes a user account.sudo deluser bob
passwd [user]Changes a user’s password.sudo passwd alice

7. Networking

CommandDescriptionExample
ping [host]Tests network connectivity.ping google.com
ifconfig / ip aShows network interfaces and IP addresses.ip a
netstat -tulnpDisplays open ports and listening services.sudo netstat -tulnp
wget [URL]Downloads a file from the web.wget https://example.com/file.zip
curl [URL]Displays or transfers data from a URL.curl https://api.github.com

8. Package Management

-Debian / Ubuntu (APT)

CommandDescriptionExample
apt updateUpdates the package list.sudo apt update
apt upgradeUpgrades all installed packages.sudo apt upgrade
apt install [package]Installs a package.sudo apt install vim
apt remove [package]Removes a package.sudo apt remove nano

RedHat / CentOS (YUM)

CommandDescriptionExample
yum updateUpdates packages.sudo yum update
yum install [package]Installs a package.sudo yum install git
yum remove [package]Removes a package.sudo yum remove httpd

9. Compression and Archiving

CommandDescriptionExample
tar -cvf file.tar [files]Creates a tar archive.tar -cvf backup.tar /home/user/
tar -xvf file.tarExtracts a tar archive.tar -xvf backup.tar
gzip [file]Compresses a file using gzip.gzip notes.txt
gunzip [file.gz]Decompresses a gzip file.gunzip notes.txt.gz
zip [file.zip] [files]Creates a ZIP file.zip archive.zip *.txt
unzip [file.zip]Extracts a ZIP archive.unzip archive.zip

10. Other Useful Utilities

CommandDescriptionExample
clearClears the terminal screen.clear
historyShows previously used commands.history
echo "text"Displays text or variables.echo $USER
dateDisplays the current date and time.date
shutdown -h nowShuts down the system immediately.sudo shutdown -h now
rebootRestarts the system.sudo reboot

Deixa un comentari

L’adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *