Skip to Content

Tips for New Linux Users: 2024-10-17

Linux Tips

Mastering Linux Management

Basic VI Editor Commands
To start vi:
Example: vi letter will open a new file called letter to edit, or if letter already exists, open the existing file.
Command Effect
vi filename Edit filename starting at line 1
vi +n filename Edit filename beginning at line n
vi +filename Edit filename beginning at the last line
vi -r filename Recover filename after a system crash
vi +/pattern filename Edit filename starting at the first line containing pattern
Updating System Packages
To update your system packages:
Example: sudo apt-get update to update the package list, followed by sudo apt-get upgrade to upgrade all packages.
Command Effect
sudo apt-get update Update the list of available packages
sudo apt-get upgrade Upgrade all outdated packages
sudo apt-get dist-upgrade Perform a distribution upgrade
sudo apt-get autoremove Remove unused packages
Using the Nano Editor
To edit files with nano:
Example: nano filename will open the file in the nano editor.
Command Effect
nano filename Open the file in nano editor
Ctrl + O Save the file
Ctrl + X Exit the editor
Ctrl + W Search for text within the file
Ctrl + K Cut the highlighted text
Finding Files with grep
To search for files containing specific text:
Example: grep -r ‘text’ /directory will search recursively for ‘text’ in all files within the directory.
Command Effect
grep ‘text’ filename Search for ‘text’ in a file
grep -r ‘text’ /directory Search recursively for ‘text’ in a directory
grep -i ‘text’ filename Case-insensitive search
grep -v ‘text’ filename Inverse search, show lines without ‘text’
Managing Processes
To manage running processes:
Example: ps aux will display a list of all running processes.
Command Effect
ps aux Show all running processes
ps -ef | grep process_name Search for a specific process
kill process_id Terminate a process by ID
kill -9 process_id Forcefully terminate a process
top Display real-time process information
Managing Users and Permissions
To manage users and permissions:
Example: sudo useradd newuser will create a new user.
Command Effect
sudo useradd newuser Create a new user
sudo passwd newuser Set a password for the new user
sudo usermod -aG group newuser Add user to a supplementary group
chmod 755 filename Change file permissions (read-write-execute)
chown user:group filename Change file ownership
Network Configuration
To configure network settings:
Example: ifconfig will display network interface information.
Command Effect
ifconfig Show network interface information
ping hostname Test network connection to a hostname
netstat -tuln Display active listening sockets
ssh user@hostname Securely log into another host
sudo ufw allow 22 Allow incoming SSH connections
Task Scheduling with Cron
To schedule tasks with cron:
Example: crontab -e will edit the user’s cron jobs.
Command Effect
crontab -e Edit the user’s cron jobs
* * * * * command Run a command at specific times
0 2 * * * command Run a command daily at 2:00 am
5 4 * * 1-5 command Run a command every weekday at 4:05 am
@reboot command Run a command at system startup
System Monitoring
To monitor system performance:
Example: top will provide a dynamic real-time view of the processes running on the system.
Command Effect
top Display real-time system processes
htop Improved version of top with color
vmstat Report virtual memory statistics
free -m Show memory usage in MB
df -h Display disk space usage in human-readable format
du -sh directory Estimate file space usage of directories
File System Navigation
To navigate the file system:
Example: cd /path/to/directory will change the current directory.
Command Effect
cd /path/to/directory Change the current directory
pwd Print the current working directory
ls List files and directories
ls -l List files with detailed information
mkdir directory_name Create a new directory
rmdir directory_name Remove an empty directory
File Manipulation
To manipulate files and directories:
Example: cp source_file destination_file will copy a file.
Command Effect
cp source_file destination_file Copy a file
mv source_file destination_file Move or rename a file
rm filename Remove a file
touch filename Create a new empty file
ln -s target link_name Create a symbolic link
chmod 755 filename Change file permissions

Edward Dan

Friday 18th of October 2024

Great article! As a newcomer to the Linux world, I found the tips incredibly useful. The section on mastering basic VI editor commands was particularly helpful, as it's something I struggle with. The clear examples for updating system packages were also a lifesaver – they made the process much easier to understand.