Linux Tips


Disk usage
    df -h; df -k  # check the total disk usage
    du -h; du -k  # check disk usage of the current directory
    
Backup
    rsync -a -v [source directory name] [target directory name]                  # backup locally
    rsync -a --delete -v [source directory name] [target directory name]         # backup locally with the "delete" option
    rsync -a -v -e ssh [source directory name] [target directory name]           # backup via SSH
    rsync -a --delete -v -e ssh [source directory name] [target directory name]  # backup via SSH with the "delete" option
    
Copy files from others
    rsync -a --copy-unsafe-links -v -e ssh [source directory name] [target directory name]  # copy via SSH including softlinked files
    
tar
    tar cvf [file name].tar [directry name]  # combine directries and files to a single file
    tar xvf [file name].tar                  # expand a file to directries and files
    tar cvzf [file name].tgz [directry name] # combine directries and files to a single file and compress
    tar xvzf [file name].tgz                 # uncompress and expand a file to directries and files
    
Figure files
    ps2pdf [].eps [].pdf   # eps -> PDF file
    convert [].eps [].png  # eps -> PNG file
    convert [].eps [].tif  # eps -> TIF file
    convert [].eps [].jpg  # eps -> JPEG file
    
File permission
    find . -type d | xargs chmod 755  # change all sub-directories to "755"
    find . -type f | xargs chmod 644  # change all files to "644"
    
Jobs
    top                            # check machine status
    ps u; ps -f; ps -u[user name]  # list user processes
    jobs                           # list background jobs
    renice +10 [PID]               # lower CPU use
    kill; kill -9 [PID]            # stop process
    
ASCII format
    nkf --unix dos.txt unix.txt  # convert DOS ASCII format to UNIX ASCII format 
    dos2unix [windows file].txt  # DOS to UNIX
    unix2dos [linux file].txt    # UNIX to DOS
    
pLATEX
    platex [file name].tex  # complie and create DVI file
    dvipdfmx [file name]    # convert to PDF file
    evince [file name].pdf  # display PDF file
    
Format new HDD
    mkfs -t ext4 /dev/sd[x]
    
Others
    ls -l | wc -l  # count the number of files in the directory (subtract 1)