Linux/Ubuntu cheat sheet
Linux/ubunut Cheat sheet
To create a new user in a Linux-based operating system, you can use the adduser or useradd command. Here are the basic commands to create a new user:
Using adduser (more user-friendly):
sudo adduser username
Using useradd:
sudo useradd username
Change password command
sudo passwd username
Access server with port change other than 22 and with key pair commands
ssh username@server_ip -p 2222
while with ssh key
ssh -i ~/.ssh/id_rsa username@server_ip -p 2222
SSH key pair generation
ssh-keygen -t rsa -b 4096
chmod command
chmod is a common command that modifies a file or directory’s read, write, and execute permissions. In Linux, each file is associated with three user classes – owner, group member, and others.
chmod 777 note.txt
chown command
The chown command lets you change the ownership of a file, directory, or symbolic link to a specified username.
Here’s the basic format:
chown linuxuser2 filename.txt
sudo chown -R odoo:odoo folder_name
add user into sudo group
sudo usermod -aG sudo newusername
pwd
Use the pwd command to find the path of your current working directory.
mkdir
cd
To navigate through the Linux files and directories
ls command
The ls command lists files and directories within a system
rm
locate command
locate -i school*note
The command will search for files that contain the words school and note
find command
Use the find command to search for files within a specific directory and perform subsequent operations. Here’s the general syntax
find /home -name notes.txt
df
Use the df command to report the system’s disk space usage
df -h
These are some acceptable options to use:
- df -m displays information on the file system usage in MBs.
- df -k displays file system usage in KBs.
- df -T shows the file system type in a new column.
du command
If you want to check how much space a file or a directory takes up,
du /home/user/Documents
Adding a flag to the du command will modify the operation, such as:
- -s offers the total size of a specified folder.
- -m provides folder and file information in MB
- k displays information in KB.
- -h informs the last modification date of the displayed folders and files.
kill command
Use the
kill command to terminate an unresponsive program manually. It will signal misbehaving applications and instruct them to close their processes.
ps ux
After knowing what signal to use and the program’s PID, enter the following syntax:
kill [signal_option] pidping command
The ping command is one of the most used commands in Linux for checking whether a network or a server is reachable
history command
With history, the system will list up to 500 previously executed commands, allowing you to reuse them without re-entering. Keep in mind that only users with sudo privileges can execute this command.
history [option]
This command supports many options, such as:
- -c clears the complete history list.
- -d offset deletes the history entry at the OFFSET position.
- -a appends history lines.
indetify laptop model
sudo dmidecode -s system-product-name
Bios information command
sudo dmidecode -t bios