Basic Unix Commands

1. When in doubt ..
man commands

Samples:
$ man talk
$
man grep

2. What's my Unix system name, OS,CPU?
$

uname -a Sample result:

SunOS hostname 5.8 Generic_108528-06 sun4u sparc SUNW, Ultra-5_10

3. Where am I (current working directory)?
$

pwd
/export/home/user

4. Who am I?
$

who ; returns all users who logged on to the system.
$ who am i ; returns only your log in name and time.

5. What is my hostname?
$
hostname

6. What is my account info?
$

finger [account] ; to see login name, real name, TTY, idle time, when & where

7. What is my default printer?
$

lpstat -t ; shows printer statistic and status

8. When pressing BackSpace it shows ^H, how do I set it to work correctly?
$

stty erasectrl-v + bs ;press ctrl-v and back space button

9. Change directory
$

cd /usr/bin
$
cd ~+ ; ~+ = cwd or "." wherein ~- previous working directory
$
cd $HOME ; changes directory to your home folder = cd ~
$
cd ../../hw1
$ cd .. ; moves one level up from your current working directory

10. List contents of the directory
$

ls *[x,X]* ; returns a listing of files that contain x or X in the file name
$
ls -R ; lists recursively that includes subdirectories
$
ls -li ; displays long listing with inode number, or -a to list hidden files

11. File permissions
$

chmod u+x, g-r myfileadd execute permission to user, remove read from group
$
chmod u=rx, g=r, o=file ; allows user to read and execute, group to read, no
read, write and execute for others

$
chmod a=rxfile ; allows user, group and others to read and execute
$
chmod 754 myfile7-> 111 in binary represents rwx for user
5-> 101 in binary represents r-x for group
4-> 100 in binary represents r-- for others
12. Read text file(s)
$
catmyfile ; alternately, you can use more myfile
$
catmyfile news mail ; read multiple files
$
cat *ing

13. Copy file(s)
$

cpmyfile newfile
$ cp * ../hw
$
cp -r /home/mydir /home/newdir ; copies everything in mydir to newdir
$
cp -p source destination ; retains existing permissions (copy ACL along)
$
cp -i source destination ; does not overwrite an existing file

14. Move files to another directory
$

mv * /home/my_account
$
mvmyfile $HOME

15. Delete file(s)
$

rm myfile
$ rmmyfile? ; removes myfile1, myfile2, myfile3 and so on.

16. Make a directory
$

mkdirmydir

17. Delete an empty directory
$
rmdirmydir

18. Delete a directory that contains files and subdirectories
$

rm-rmydir ; removes recursively all files and subdirectories

19. Symbolic link (can span/accross file systems)
$

ln -sfile1link1 ; uses ls -li to see link1-> file1 with 2 different inodes.
symbolic link always has a=rwx permissions

20. Hard link (files contain the same inode, can not span file systems)
$

No comments:

topics