File System Commands
File Structure
- Show file system, list -l, all -a, human readable file sizes -h
df -lah
Directory and File Size
- Show recursive files and directory sizes starting in the current directory, -h make file size human readable, -c show total size
du -hc *
- Show files and directories size in the current directory, -s summarize, combines directories and files, -h make file size humane readable, -c show total size
du -shc ./*
- Show total current directory size, includes all recursive files and directories
du -sh ./
- Show files and directories size in the current directory, -s summarize, combines directories and files, -h make file size humane readable, pipe through 'sort -h' to sort by size
du -sh * | sort -h
List Directories
- Show files and directories in -l list format, -a all, -h human readable file size
ls -lah
- Show files, sort by date, human readable
ls -lath
- Show number of files in a directory
ls | wc -l
- List only subdirectories in current directory, ls -d1 */ will list vertically
ls -d */
Copy Files
- cp, copy command, using the {,-bak} at the end creates a copy with an appended extension, result: /home/usr/filename.jpg-bak. Second example matches all with the same extension and adds an appeneded extention.
cp /home/usr/filename.jpg{,-bak}
cp /home/usr/*.jpg{,-bak)
Navigate Directories
- Show current directory
pwd
- Change directory
cd /foo/bar/directory
- Move up one directory and move up two directories.
cd ..
cd ../..
- Takes you back to the last directory you were in, very useful
cd -
Rename File Extensions
- Rename file extenstion from '.php.bak' to 'php'
rename .php.bak .php *
Rsync Commands
- Copy remotedir/* to localdir/
rsync -ve ssh usrname@remoteipaddress:/path/to/remotedir/* /path/to/localdir/
- Copy, recursively, remotedir/* to localdir/
rsync -rve ssh usrname@remoteipaddress:/path/to/remotedir/* /path/to/localdir/
Other File System Commands
See Grep, Find, and AWK for other useful file system commands.