Moving Around the Filesystem
- pwd - print working directory
- cd - change directories
Manipulating Files and Folders
copy, move, remove, list, create, permission, owner
- cp - copy
e.g., cp file foo : an new copy of file whose name is foo
- mv- moves
e.g., mv file foo : rename original file to foo
e.g., mv foo ~/Desktop: move file foo to your desktop
e.g., sudo mv foo /user/.../Desktop : sudo need full path name instead of ! in place of home directory
- rm - remove file not directory containing files
- ls - list files in your current directory
e.g., ls ~: show files in your home directory
- mkdir - making directory
mkdir music: create a music dirctory
- chmod: change permission/mode
user/group/world
e.g., a file allow everybody to read but only user could write => rwx r-- r--
e.g.,add a permission -> chmod g+x file
- chown: change the user and group ownership of a file
e.g., chown jim file : change the ownership of file to jim
System Information Commands
hardware, network, operating system disk space, process
- df : display filesystem disk space usage for all partitions
e.g., df -h (human readable, MB, GB)
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 184Gi 175Gi 9.6Gi 95% 45826245 2513597 95% /
devfs 191Ki 191Ki 0Bi 100% 662 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
/dev/disk0s4 281Gi 274Gi 6.1Gi 98% 1049759 6366153 14% /Volumes/BOOTCAMP
|
- free: free and used memory in the system
e.g., free -m : gives the information using megabytes, which is probably useful for current computers
- top: running processes and system resources, including CPU, RAM, swap usage, and total number of tasks being run
e.g., top
e.g., to exit , press Q
- uname -a: CHECKING WHICH KERNEL you are using
print all system information, including machine name, kernel name, verison , and a few other details
- lsb_release -a: print version information for the linux release you’re running
user@computer:~$ lsb_release -a
LSB Version: n/a
Distributor ID: Ubuntu
Description: Ubuntu (The Breezy Badger Release)
Release:
Codename: breezy
- ifconfig: reports on your network interfaces
- iwconfig: wireless network adapters and the wireless-specific information from them, such as speed and network connected
- ps: view all proceess running on the mahcine
The following commands list the hardware on your computer, either of a specific type or with a specific method. They are most useful for debugging when a piece of hardware does not function correctly.
9. lspci : all PCI buses and devices conneced to them, including nerwork cards and sound cards
10.lsusb: list all USB buses and any connected USB devices, such as printers and thumb drives
11.lshal: lsit all deveices the hardware abstraction layer(HAL) knows about, hwich shouldb e most hardware on your system
12.lshw: lists hardware on your system, including marker, type, and where it is connected
Searching and Editing Text Files
search, search and replace, concatenate, open to edit/view
- grep-search inside a number of files for a particular search pattern and print matching lines
e.g,. grep blah file : will search for the text “blah” in the file and then print any matching lines
- sed- stream editor- allows searhc and replace of a particular string in a file
e.g., sed s/cat/dog/g pets : search the string “cat” and replace it with “dog” in a file named pets
Both grep and sed are extremely powerful programs. There are many excellent tutorials available on using them, but here are a few good Web sites to get you started:
3. cat : concatenate
e.g., cat filename : display the contents of the file
e.g., cat filename file: adds the contents of the first file to the second
4. nano: simple text editor
e.g., nano filename
commands listed at the bottom of the screen are accessed via pressing Ctrl followed by the letter
5. less: viewing text files as well as standard output [TEXT MODE]
ls | less : pipe another command through less to be able to see all the output
Dealing with Users and Groups
add, delete,
- adduser:
e.g., sudo adduser $loginname : this creates user’s home directory and default group. It promprs for a user passowrd and the nfurther details about the user
- passwd:
e.g., sudo passwd joe : change Joe’s password
- who:
e.g., who : tell you who is currently logged into the machine
- addgroup:
e.g., sudo addgroup $groupname
- deluser:
e.g., deluser -remove-home : to remove user’s file and home directory
- delgroup:
you cannot remove a group that is the primary group of any users
Getting Help on the Command Line
- --help
- man (manual)
- -h or -help
- man -h
- man --help
e.g., man mv - bring up the mv(move) manual
- Arrow keys: move up and down the man file by using the arrow keys
- q - quit back to the command prompt by typing q
- man man: bring up the manual entry for the man command, which is a good place to start
- man intro: display the introduction to User Commands, which is a well-written, firly brief instrocution to the linux command line
- info info
Searching for Man Files
- man -k foo: serach the main files for “foo”
e.g., man -k nautilus
- man -f foo: serch only the titles of your system’s man files
e.g., man -f gnome
man -f foo is the same as the whatis command
Using Wildcards *(multiple), ?(Single),[](Specify)
look at or use multiple files at the same time, e.g., delete all .rar files or move all .odt files to another directory
- * matches any number of characters.
For example, *.rar matches any file with ending .rar
- ? mathces any single character
For example, ?.rar mathces a.rar but not ab.rar
- [characters] matches any of the characters within brackets.
For example, [ab].rar matches a.rar and b.rar but not c.rar
- [!characters] matches any characters that are not listed.
For example, [!ab].rar matches c.rar but not a.rar or b.rar.
Executing Multiple Commands
Often you want to execute several commands together,
either by running one after another or
by passing output from one to another
Running Sequentially
e.g., run regardless of whether or not preceding commands succeed
lspci ; lsusb
e.g., ./confiure && make && make install
Passing output
pipe
e.g., ls | less: allow you to view the contents of the ls more easily
Moving to More Advanced Uses of the Command Line
- A Practical Guide to Linux Commands, Editors and Shell Programming by Mark G. Sobell (Prentice Hall, 2005) is a good book for any user of the shell in Linux to have on his or her bookshelf.
- LinuxCommand.org is an excellent Web site designed to help people new to using the command line.
- The Linux Documentation Project is an excellent and free resource for many things Linux.
Reference:
http://www.computerworld.com/article/2598082/linux/linux-linux-command-line-cheat-sheet.html
http://www.computerworld.com/article/2598082/linux/linux-linux-command-line-cheat-sheet.html
No comments:
Post a Comment