Linux Tips
Mastering Linux Management
Basic Shell Navigation Commands
To navigate directories in the shell:
Example: cd Documents will change the current directory to Documents.
Command | Effect |
---|---|
cd .. | Move up one directory |
cd ~ | Change to the home directory |
cd – | Switch to the previous directory |
ls -l | List files in long format |
ls -a | List all files, including hidden ones |
Copying Files and Directories
To copy files or directories:
Example: cp file1.txt file2.txt will copy file1.txt to file2.txt.
Command | Effect |
---|---|
cp source destination | Copy source to destination |
cp -r dir1 dir2 | Copy directory dir1 and its contents to dir2 |
cp -i source destination | Prompt before overwriting destination |
cp -u source destination | Copy only if source is newer than destination |
cp -v source destination | Verbose output showing files being copied |
Removing Files and Directories
To delete files or directories:
Example: rm file.txt will remove file.txt from the system.
Command | Effect |
---|---|
rm filename | Remove the specified file |
rm -r directory | Remove directory and its contents recursively |
rm -f filename | Force removal without prompts |
rmdir directory | Remove empty directory |
find . -name “*.txt” -exec rm {} \; | Remove all .txt files in the current directory |
Downloading Files with wget
To download files from the web:
Example: wget http://example.com/file.zip will download file.zip from the specified URL.
Command | Effect |
---|---|
wget url | Download file from the specified URL |
wget -O filename url | Download file and save as filename |
wget -c url | Continue a partially downloaded file |
wget -r url | Download files recursively from the specified URL |
wget -q url | Download file quietly (no output) |
Using Git for Version Control
To manage project versions:
Example: git clone https://github.com/user/repo.git will clone the repository to your local machine.
Command | Effect |
---|---|
git init | Initialize a new Git repository |
git clone url | Clone a repository from the specified URL |
git status | Show the status of changes |
git add filename | Add file to staging area |
git commit -m “message” | Commit changes with a message |
Managing File Permissions
To change file permissions:
Example: chmod 755 script.sh will set the script.sh file to be executable.
Command | Effect |
---|---|
chmod 755 filename | Set permissions to read/write/execute for owner, and read/execute for others |
chmod u+x filename | Add execute permission for the file owner |
chmod g-w filename | Remove write permission for the group |
chown user:group filename | Change the owner and group of the file |
ls -l | List files with permissions and ownership details |
Searching for Files with find
To locate files on your system:
Example: find /home -name “*.txt” will search for all .txt files in the home directory.
Command | Effect |
---|---|
find path -name filename | Find files by name |
find path -type d | Find directories |
find path -type f | Find files |
find path -size +100M | Find files larger than 100 MB |
find path -mtime -7 | Find files modified in the last 7 days |
System Monitoring with top
To monitor system processes:
Example: top will display running processes in real-time.
Command | Effect |
---|---|
top | Display real-time system processes |
htop | Enhanced version of top with more features |
ps aux | List all running processes |
kill PID | Terminate the process with the specified PID |
killall processname | Terminate all processes with the specified name |
Network Configuration with ifconfig
To view and configure network interfaces:
Example: ifconfig eth0 will display the configuration of the eth0 interface.
Command | Effect |
---|---|
ifconfig | Display current network interface configurations |
ifconfig eth0 up | Activate the eth0 interface |
ifconfig eth0 down | Deactivate the eth0 interface |
ping host | Check the connectivity to a host |
traceroute host | Show the route packets take to a network host |
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!
Edward Dan
Wednesday 23rd of October 2024
Great tips for new Linux users! I particularly found the command line shortcuts really helpful for boosting productivity. Thanks for sharing this valuable information!
THZ
Sunday 13th of October 2024
Very good