LampPi

 

Home

Students: Common unix commands

Students: Common unix commands

1. ls
Desc: to list the directory
(list)
$ ls
$ ls -l
$ ls -al

2. cd
Desc: to change to a directory
(change directory)
$ cd /home/pi

3. pwd
Desc: shows where you are (in what directory)
(present working directory)
$ pwd

4. mkdir
Desc: Create a new directory
(make directory)
$ mkdir my_stuff

5. whoami
Desc: Shows who you are
(who am i)
$ whoami

6. top
Desc: shows stats about the server
(top)
$ top
Note: press "q" to quit top and get back to the command prompt

7. uptime
Desc: tells the server uptime and load averages
(up time)
$ uptime

8. chown
Desc: used to change ownership of a file or directory
(change ownership)
$ chown pi:pi myfile.txt

9. chmod
Desc: used to change permissions on a file
(change file or directory permissions)
$ chmod u+r myfile.txt
$ chmod ug+r myfile.txt
$ chmod ugo+r myfile.txt
$ chmod u-r myfile.txt
$ chmod ug-r myfile.txt
$ chmod ugo-r myfile.txt
$ chmod ugo-rw myfile.txt
Note: You should be able to do a "ls -l" and understand the permission settings
Note: "u"=User, "g"=Group and "o"=Other

Example 1:
$ ls -l
drwxr-xr-x 6 pi pi 4096 Jun 26 10:44 backups
dr-xr-xr-x 3 pi pi 4096 Jun 2 10:45 ftp
drwxr-xr-x 5 pi pi 4096 Jun 23 11:08 projects

Using "backups", the first position is "d" for directory (backups is a directory)
Positions 2 through 4 are the User (or owner): rwx is read, write, execute
Positions 5 through 7 are the Group: r-x is read, no write, execute
Positions 8 through 10 are Other: r-x is read, no write, execute

Example 2:
$ ls -l
drwxr-xr-x 2 pi pi 4096 Jun 22 14:36 images
-rw-r--r-- 1 pi pi 21112 Jun 25 18:45 index.php
drwxr-xr-x 5 pi pi 4096 Jun 22 14:38 templates

Using "index.php", the first position is "-". This is a file, not a directory
Positions 2 through 4 are the User (or owner): rw- is read, write, no execute
Positions 5 through 7 are the Group: r-- is read, no write, no execute
Positions 8 through 10 are Other: r-- is read, no write, no execute

10. cp
Desc: used to copy a file
(copy)
$ cp /home/pi/my_stuff.php /home/pi/backups

11. mv
Desc: to move or rename a file
(move)
$ mv /home/pi/my_stuff.php /home/pi/my_other_stuff.php

12. man
Desc: to display documentation on a command (help)
(manual)
$ man chmod

13. ps
Desc: to report on a process status
(process status)
$ ps -ax
$ ps
$ ps -ax | grep 12345

14. tar
Desc: to zip or unzip a file or directory
(tar)
$ tar -xvf my_tar_file.tar

15. gunzip
Desc: to unzip a file or directory
(gunzip)
$ gunzip my_tar_file.tar.gz

16. unzip
Desc: to unzip a file
(unzip)
$ unzip my_zip_file.zip

17. rm
Desc: to delete (remove) a file or directory
(remove)
$ rm myfile.txt
Note: Be very careful using the rm (remove) command.

18. ^c
Desc: this may stop something you are doing

19. q
Desc: this may stop something you are doing

20. df
Desc: to see file system disk space usage
(disk file)
$ df -h
$ df -ak

21. uname
Desc: to see the OS system information
$ uname -a

22. sudo
Desc: sudo is used by a non-root user to execute as root.
$ cd /home/pi
$ sudo cp /etc/hosts /home/pi
$ sudo chown pi:pi hosts
Note: The reason you (pi user) can use sudo is because "pi" is listed in the sudoers file.
Note: Be careful using this as it will execute as root
Note: "root" is the super-user on unix systems

23. exit
Desc: this will end your ssh or PuTTY shell session
$ exit

24. scp
Desc: Copy files or directories to a remote host
$ cd /mydirectory
$ scp myfile user@remote.host:/myremotedirectory
$ scp -r mysubdirectory user@remote.host:/myremotedirectory

25. find
Desc: Find a file name
$ find . -name myfilename

26. grep
Desc: To find any string
$ grep -r -e MyWord /mydirectory

27. netstat
Desc: Displays various network information
$ netstat
$ netstat -an | grep myword

28. ps
Desc: Provides information on current processes
$ ps
$ ps -efl | grep myword

29. ifconfig
Desc: Configure and provide network interface information
$ ifconfig


About

Contact

Links

Site Map

© LampPi 2018