Tuesday, October 20, 2015

[Basic Linux Command]

Moving Around the Filesystem
  1. pwd - print working directory
  2. cd - change directories


Manipulating Files and Folders
copy, move, remove, list, create, permission, owner
  1. cp - copy
e.g., cp file foo : an new copy of file whose name is foo
  1. 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
  1. rm - remove file not directory containing files
  2. ls - list files in your current directory
e.g., ls ~: show files in your home directory
  1. mkdir - making directory
mkdir music: create a music dirctory
  1. 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
  1. 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
  1. 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


  1. free: free and used memory in the system
e.g., free -m : gives the information using megabytes, which is probably useful for current computers
  1. 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
  1. uname -a: CHECKING WHICH KERNEL you are using
print all system information, including machine name, kernel name, verison , and a few other details


  1. 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


  1. ifconfig: reports on your network interfaces
  2. iwconfig: wireless network adapters and the wireless-specific information from them, such as speed and network connected
  3. 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
  1. 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
  1. 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,
  1. 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
  1. passwd:
e.g., sudo passwd joe : change Joe’s password
  1. who:
e.g., who : tell you who is currently logged into the machine
  1. addgroup:
e.g., sudo addgroup $groupname
  1. deluser:
e.g., deluser -remove-home : to remove user’s file and home directory
  1. delgroup:
you cannot remove a group that is the primary group of any users

Getting Help on the Command Line
  1. --help
  2. man (manual)
  3. -h or -help
  4. man -h
  5. man --help
e.g., man mv - bring up the mv(move) manual
  1. Arrow keys: move up and down the man file by using the arrow keys
  2. q - quit back to the command prompt by typing q
  3. man man: bring up the manual entry for the man command, which is a good place to start
  4. man intro: display the introduction to User Commands, which is a well-written, firly brief instrocution to the linux command line
  5. info info


Searching for Man Files
  1. man -k foo: serach the main files for “foo”
e.g., man -k nautilus
  1. 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
  1. * matches any number of characters.
For example, *.rar matches any file with ending .rar
  1. ? mathces any single character
For example, ?.rar mathces a.rar but not ab.rar
  1. [characters] matches any of the characters within brackets.
For example, [ab].rar matches a.rar and b.rar but not c.rar
  1. [!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

No comments:

Post a Comment