Useful linux Commands For Server Admins
SSH Commands
Transferring Files from local to remote machine using SSH
1 |
scp /path/to/file username@a:/path/to/destination |
AWK Command:
AWK is not a command it is a text interpretation language developed by “Aho, Weinberger, and Kernighan in 1970 and thats why it got this name.
awk works on mostly linux systems, and it is very helpful for text processing.
1 |
echo $snapshot | awk -F ‘,’ ‘{ print id=$1 }{ print date=$2 }’ |
1 |
snap_shot_list=$(cat $TMP_FILE2 | grep ${volume} | awk ‘{ print $2″,”$5 }’) |
Dig Command
Dig stands for domain information groper , it is good for troubleshooting DNS related issue.
1 |
dig example.com any |
Alternative of dig command is host command , example is below -
1 |
host -t MX cpanel4j.com |
It will give you output as below -
1 |
cpanel4j.com mail is handled by 10 vsmtp.nixhero.com. |
Search Commands
searching for a file by name -
1 |
find /where/to/search -name name_of_file.txt |
Searching For text into a file
1 |
grep “search query” /path/to/file |
Creating Symbolic Links
1 2 |
ln -s {/path/to/file-name} {link-name} ln -s /shared/sales/data/file.txt sales.data.txt |
Assigning Output of a command to a variable:
1 |
var1=$(ls) |
Here Command-
This command is similar to perl‘s here command.
1 2 3 4 5 6 |
cat <> /var/spool/cron/root write anything here till that above mentioned text EndXML |
This will shell code is useful if you want to write multiple lines to a file.
“>” is used to overwrite the file and “»” is used to append that file.
If Conditions:
checking whether string is empty or not-
1 2 3 4 |
if [ -z “$string” ]; then echo “String is empty” fi |
Email Related Commands -
Delete all emails in the queue-
exim -bp | awk ‘/^ *[0–9]+[mhd]/{print “exim -Mrm ” $3}’ | bash
Print a list of messages in queue
exim -bp
GREP Command:
search for a pattern in php files recursively -
1 |
grep -rn –color –include=*.php “pattern”; |
here “r” mean recursively and “n” mean display line number.
Other
UserFriendly file permission view -
1 |
stat -c “%a %n” * |
Recent Comments