Monday, June 11, 2018

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 

No comments:

Post a Comment