get file permissions in octal mode
stat -c "%a %n" *
List files
ll / ls -l
Changing directory permissions
chown -R root:root nameofthefolder
chmod 775 nameofthefolder
chmod -R g+w nameofthefolder
Copy directory (keeping owners and permissions)
sudo cp -rp /home/vivek/data/ /nas/home/vivek/archived/
Move directory
mv /home/vivek/data/ /nas/home/vivek/archived/
Link files
ln -s /path dirname
Delete files as root
rm -rf
Zipping directory
zip -r myvacationpics.zip /home/you/pics/
zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*
(excluding folders)
Directory sizes
du -sh dir/
– Directory size, h – detailed, sh – summary
df -h
– Filesystem
Following log files with
tail -f /var/log/apache2/error.log
Finding a File Containing a Particular Text String In Linux Server *
grep -R (-l) "string" /var/www/site/
Latest modified files of current directory
find $1 -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head
with white spaces in the names
find $1 -type f | xargs stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head
without white spaces in the names
Search
./find.sh ****
find ./ -maxdepth 2 -type d -name "*$1*"