Useful Unix Commands and Tips - Part 3
Let us learn about df, du, sftp and scp commands in this part of the series:
du:
1) To know the percentage of disk space used at mount level:
df -kh
2) To sort disk usage in a directory in human readable format:
du -sh * | sort -rh
3) If multiple mounts uses common path. du command on common path includes storage used in all mounts. If we want find disk used by only common directory path and not device mounted on common path, need to use –exclude clause of du as shown above.
du -sh --exclude=/directory {target-directory/*}4) To find largest directories:
du -S | sort -n | tail -20
5) To find directories with size greater than 1 GB:
du -h --max-depth 50 /orasoa/common/ 2>/dev/null | grep '[0-9]G>' | sort -h
6) du usually don’t include hidden directories/files during disk usgage calculation. To include hidden files/dirs:
du -sk * .[a-zA-Z0-9]*
7) -d option prevents du from following file system boundaries. For example, to determine disk usage on the root file system but not any other file systems: du -dsk /
sftp:
1) To connect to sftp by specifying key file location:
sftp -oIdentityFile=/home/ramesh/.ssh/id_rsa username@sftpServerName
2) To connect to sftp server that is listening on a port other than 22:
sftp -oPort=2222 username@sftpServerName
3) We can’t password programatically in scp and sftp. We have to use key based authentication or some other tools like lftp.
4) SCP command can be used to transfer file between two linux boxes:
scp -r <file/dir> oracle@hostname:/<dest-directoryname>
5) When we transfer files from windows system to unix, windows line endings need to be converted into unix line endings. Otherwise, unix programs will fail. We got lot production issues due to this. Use following to approaches to do conversion:
dos2unix HCParse.sh HCParse.sh
sed -i -e 's/r$//' scriptname.sh # If dos2unix is not installed.
Comments
Post a Comment