UNIX-1.3 UNIX Commands and Options


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

du – data usage
du -sh – find how much disk space used in current directory

df – data file system
df -h – find disk space usage

cp – copies files
cp file1 file2 – copy file1 to file2
cp file1 dir/file2 – copy file1 to file2 in dir
cp file1 dir/ – copy file1 to dir with same filename
cp -rf dir1 dir2 – recursively copy dir1 to dir2
cp -i file1 file2 – prompt before overwriting file2
cp file1 file2 file3 dir1 – copy multiple files to a directory
cp -p file1 file2 – by default, permission is not preserved, use -p to do that
cp -s file1 link1 – create soft link to file1

mv – change/move files
mv file1 file2 – change filename from file1 to file2
mv -i file1 file2 – prompt before overwriting
mv file1 dir1 – move file1 to dir1
mv dir1 dir2 – move dir1 to dir2 if dir2 exists, else change name from dir1 to dir2

head – display lines in file from beginning
head file1 – display first 10 lines of file1
head -100 file1 – display first 100 lines of file1

tail – display lines in file from end
tail file1 – display last 10 lines of file1
tail -100 file1 – display last 100 lines of file1

rm – remove file or directory
rm file1 – remove file1
rm -rf dir1 – remove entire directory, never prompt
rm -i dir1 – prompt before removing

mkdir – create directory
mkdir dir1 – create dir1
mkdir -m777 dir1 – create dir1 with specified permission
mkdir -p dir1 – ignore error if dir1 already exists

tar – archive file
tar zcvf tarfilename.tar file1 file2 file3 – archive all these files into one tar ball, compressed
tar xvf tarfilename.tar – extract files from a tar ball
tar rf tarfilename.tar extra.txt – append extra.txt to existing tarfilename.tar (tarfilename.tar is not compressed)
tar tvf tarfilename.tar – list out files in tar ball

gzip – compress file
gzip file1 – compress file1, new filename will have .gz extension
gzip -d file1.gz – decompress file1.gz

chmod – change permission
chmod 777 file1 – change permission for file1 (rwxrwxrwx)
chmod +x file1 – give executable permission for all to file1 (+r, +w)
chmod u+x file1 – give executable permission for owner to file1 (g+x, o+x)
chmod -R 777 dir1 – change permission for all contents in dir1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s