Monday, June 11, 2018

Linux .profile shortcuts


This is regarding the alias names in .profile on your Linux servers. By adding the alias names in your .profile you can reduce the work load of typing full command.

Instead of typing ‘ls –ltr‘, you can just type ‘l’ after adding this entry in your .profile file:

alias l='ls -ltr'


Please follow this procedure to add the alias names in your .profile file.

  • Login to the linux server
  • Type cd (it will take you to your home path)
  • Type ls -latr .profile ( It will list your .profile file)
  • Using VI editor open the .profile and add the alias names to it. Here is a sample:

#
# Adding the alias names
#
alias l='ls -ltr'
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias dev3logs='cd /storage/DEV3/logs'
#


Save your .profile file after adding the entries and exit your session.
Re login to the server to get these changes effected.

Basic Linux filesystem commands

Quick reference for some basic filesystem commands:

cd 
Go back to user directory 
rm –f –r directoryname 
Delete folder with all files and subdirs without prompt 
cp filename newname 
Copy filename to the new filename 
mv filename newname 
Move or rename file 
Ls -ltrA
List all files:
 "-A" including hidden dot files, but not the current or parent directory "." and ".."
 "-t" and "-r" sort by modification time; in reverse order (oldest first)
 "-l" as a list (one file per line, including size, date, permissions)
chmod <550> <file> <file>
Change chmod.... 
stat --format '%a' filename 
List chmod for the filename 
df 
Show directory space usage 
du –m 
ls -l --block-size=MB 
Show files and size 
find . -type f -size +100M -exec ls -lh {} \; 
List files bigger than 100MB 
find . -type f -size +100M -exec gzip "{}" \; 
Gzip all files over 100M under current path (incl. Subdirs) 
find / -name *sometext* 2> /dev/null 
Find files (from root "/") with sometext in the name, suppressing errors (redirecting error output to null) 
find / -type f -iname cmp_rule_*.dat 2>/dev/null 
Find (from /) ; files only (-type f) ; with case insensitive name (-iname) cmp_rule_<anything>.dat ; redirect stderr to null 
mv `find . -maxdepth 1 -mtime +90` archive/ 
Move all files in the current folder (not recursive "-maxdepth 1") that were modified more than 90 days ago "-mtime +90" to the archive subfolder