There are certain commands frequently used for server management in Linux. With these commands, you can access and perform many basic operations on your server.
Basic Commands
pwd : prints the current directory you are in.
cd : used to navigate between directories. (Example: cd /home takes you to the /home directory.)
ls : lists all files and folders in the current directory. It has many parameters; type “man ls” for full details.
ls -l : produces a detailed list with date, file owner, and permissions.
ls -a : displays all files including hidden ones. Parameters can be combined. (Example: ls -la)
ls -lS : sorts files by size.
ls -lh : shows file sizes in MB, GB, TB.
ls -lt : sorts files by creation and modification date.
mkdir : used to create a new folder.
rm : used to delete files or folders. Type “man rm” for useful parameters.
touch : used to create a new file.
tail : shows the last output of a file. (Example: tail -20 /root/file.txt shows the last 20 lines.)
head : works opposite to tail, shows the first output of a file. (Example: head -10 /root/file.txt)
nano : file editing tool. Open with nano /root/file.txt, exit with CTRL + X.
service : used to start, query status, or stop services. (Example: service mysql restart)
ps : shows running applications. Most common usage: ps aux, which lists all running apps with CPU and RAM usage.
kill : terminates an application by its PID number. (Example: kill -9 PIDNUMBER)
killall : closes the specified application along with all its running instances.
who : displays users connected to the server.
uname : provides OS information. Use uname -a for kernel version.
df : shows disk usage. Most common: df -h, which displays in MB, GB, TB.
watch : continuously runs the command specified in quotes.
scp : transfers files via SFTP or sends commands to another SSH.
ftp : used for FTP connections and operations.
wget : used to fetch data from any URL.
passwd : used to change user password. If connected as root, you can change the root password.
man : displays parameters of commands.
reboot : restarts your server.
shutdown : used to completely shut down your server.
uptime : shows server uptime and load status.
tar : used for file compression or extraction. (Example: tar -zxvf to extract tar.gz, tar -cvf to compress)
unzip : extracts zip compressed files.
zip : compresses files into zip format.
gunzip : extracts gz compressed files.Useful Operators
| : pipe character — used to combine two commands at once.
&& : runs the next command only if the first one succeeds.
; : runs the next command after the first one regardless of result.
grep : used for filtering, usually combined with pipe.
cut : used to cut data from command output.
sort : used to sort command outputs.
uniq : reporting command, used to statistically sort repeated items in output.
cat : prints file contents directly to screen.
more : helps read long command output more comfortably, used with pipe.Examples
ls -la /home | grep netinternetFilters files and folders in /home directory that contain “netinternet”.
ps aux | grep -v httpdShows all results from ps aux output except lines containing “httpd”.
cat /home/netinternet.txtPrints the netinternet.txt file to screen.
date | cut -dE -f1Cuts the output at the first occurrence of “E”: Thu Jul 18 00:36:15
cat test.txt | sortSorts all dates from smallest to largest.
cat test.txt | uniq -cPrints repeated lines statistically.
cat /home/netinternet.txt;cat /home/net.txtPerforms two operations in a single line.
service mysql restart&&cat /home/netinternet.txtIf the first operation succeeds, the second command runs.
Leave a Comment
* Your comment will be published after approval.
Comments
0No comments yet. Be the first to comment!