Terminal

LINUX TERMINAL

1) FOLDERS IN LINUX


 * / || The root folder, where everything starts, and everything is contained in this folder (or under subfolders of this folder). ||
 * /bin || Contains system-critical programs (**bin**aries) ||
 * /boot || Contains files needed for booting (be careful!) ||
 * /dev || Contains files which can be used to directly access your hardware (files to manipulate all your hard drives etc)(**dev**ice) ||
 * /etc || Contains mainly configuration files for various programs/system stuff. ||
 * /home || Contains a folder for each user (except root) where they can store their personal files. ||
 * /lib || A folder for system-critical libraries. ||
 * /root || The home folder for root - the super-administrator (generally will be locked to normal users so you can’t take a peek). ||
 * /media || Contains folders for the media attached to your system (CDs, DVDs and USB sticks etc) ||
 * /mnt || Mounted file systems ||
 * /ofw || open firmware ||
 * /opt || Optional software - like desktop environments etc. ||
 * /proc || A dynamic directory - maintains information about the state of the system, including currently running processes ||
 * /root || root users home, access not allowed to most users ||
 * /sbin || Contains essential programs only designed to be run by root. ||
 * /security || security ||
 * /selinux || security enhanced linux ||
 * /sys || system files ||
 * /srv || data for services provided by this system ||
 * /tmp || Temporary files, deleted every restart. ||
 * /usr || Stands for Unix System Resources (not user as is commonly said). Contains lots of stuff, so I’ll look into it below. ||
 * /usr/bin || Contains virtually every single program you use. ||
 * /usr/lib || Contains virtually every system library that programs require to run. ||
 * /usr/local || Contains programs that you have manually compiled rather than installed from a package. ||
 * /usr/sbin || Contains virtually every program designed to be run by the super-administrator, root. ||
 * /usr/X11R6 || Houses files which power the X Window System (X version 11 release 6), which is the basis of almost every graphical environment. ||
 * . || Dot (that’s a full stop) means the current directory. Mainly used to start programs in the current directory (like **./configure** for example). ||
 * .. || Two full stops means the directory one up from the current directory. So if you’re in **/home/peter** going to **../** would take you to **/home**. ||
 * ~ || The tilde symbol means your home directory - so that will be **/home/yourusername**. ||

[username@hostname location]$ example [olpc@xo-11-4A-0B ~]$ ~ represents your home folder
 * the command line prompt**:

FILE INFORMATION ls lists files (black) and folders (blue) ls -a = lists **a**ll files, including hidden files, which begin with a dot (.) ls -l = l for long, lists files with details such as date, permissions, size (in bytes) ls -lh = long and human readable, eg. size in K not bytes ls –p distinguishes between directories (by adding / at the end of each directory) and regular files ls –t lists contents by date of their creation, latest first ls --help: provides detailed information about each command

pwd print working directory file fileName: tells you what **type** of file

PERMISSIONS folder: sudoku.activity $ ls -lh


 * type? || owner || group || world || duplicates num? || owner || group || file size || date || file name || colour ||
 * - || rw- || r-- || r-- || 1 || olpc || olpc || 54K || 2008-09-28 12:45 || sudoku.py || black ||
 * - || rwx || r-x || r-x || 1 || olpc || olpc || 687 || some date || runit.sh || green ||
 * d || rwx || r-x || r-x || 4 || olpc || olpc || 0 || some date || resources || blue ||

chmod = change the mode of each file chmod a+x trialfile; make it a shell script chmod ug-w trialfile ;prevent writes by everyone, even you chmod ug+x trialfile ;make it executable chmod ug+w trialfile ;add write back in

ug??????????????????

NAVIGATION cd = change directory cd / or cd /. root cd ~ or cd home folder cd .. up one level cd. current directory cd - previous directory and also shows the path of where you have jumped to

MANIPULATING FILES cp copy specified files, eg. to copy a file from your USB to your home folder, first, navigate to your USB and then: cp filename ~ or cp filename /home/olpc cp file1 file2 file3 ~ = copy multiple files to your home folder cp -r copy specified directories (folders), eg. cp -R adir /tmp will copy the directory and all its files to /tmp (r = recursive)

rm remove specified files rm * remove all files rm * -r remove all files and folder recursively (but still prompts for write protected files)

mv = rename or move specified files or directory, eg. mv test test1, will rename test to test1

mkdir make directory, eg. mkdir "test"

touch = updates the access and modification times of each file to the current time eg. touch -m filename = changes only the modification time eg. touch newfile = creates an empty new file, interesting

To run an executable from current directory $cmdline ="./filename"... ./ signifies that it should look in the current directory. It wont run by just including the filename unless the directory is in the PATH.

MISCELLANEOUS

alsamixer access to volume controls

SYSTEM INFO

df -h = shows diskspace usage (FileSystem) for all partitions in MB, GB (-h option means human readable) free -m = amount of free and used memory in the system, in MB top = shows %CPU and %memory being used by running processes (press q to exit) uname -a = system information, including machine name, kernel name, version ifconfig = reports on system's network interfaces, eg. eth0, msh0 iwconfig = shows wireless network adapters ps = shows processes running PID (process ID number) kill = kill a process, use ps to find out the process ID and then kill PID, whatever number

HARDWARE

lspci = lists all PCI buses and devices connected to them lshal = lists hardware (HAL = hardware abstraction layer)

SEARCH AND EDIT

find. = lists all files in current directory and subdirectories (note the dot after find) find. -name fav\* = lists all files in current directory and subdirectories beginning with fav find. -iname fav\* = same as above but iname is not case sensitive, whereas name is case sensitive The wildcard character is escaped with a slash so BASH sends a literal asterisk to the find utility as an argument instead of performing filename expansion and passing any number of files in as arguments. This 'gotcha' is important. Be aware of the characters which the shell attaches special meaning to. find /usr -iname favoritesview.py = search in /usr and find the path to the favoritesview.py file

grep i s a program to search for strings inside a file grep blah fileName = search for the text blah in the file and print any matching lines (global / regular expression / print) grep -R "class FavoritesView" /usr/lib/python2.6/site- packages/jarabe/desktop = weird way of finding favoritesview.py?since you have to know where it is first

sed Stream EDitor, search and replace of a particular string, eg. sed s/cat/dog/g fileName finds cat and replaces it with dog in file

cat = concatenate cat filename = displays contents of file less cat filename | less: displays contents of file which you can navigate through | is a pipe. Press q to exit back to command prompt cat file1 file2: adds file2 to file1

some command | less some command | more the difference between | more and | less is that | less allows backward movement in the file (more convenient)

nano fileName: enter a text editor vi fileName: enter another text editor

REDIRECT The symbols >, > are used to redirect streams of information, input and output to and from files and processes.

ls –a > foo = send list of all files in current directory to a file called foo ls –a >> foo = appends (without overwriting) the list to an already existing file foo

USERS and ADMIN who: tells you who is currently logged on adduser: deluser:

sudo: supervisor do? sudo adduser $loginname su -l (lower case L for login) "make the shell a login shell" (translation?) su -c = pass a single command to the shell, eg. su -c 'cp file1 file2 file3 ~' (put the command in quotes) exit: exit from bash as superuser and resume as normal user

DOWNLOAD and INSTALL wget = GNU Wget is a simple computer program that retrieves content from web servers, and is part of the GNU Project. Its name is derived from World Wide Web and get, connotative of its primary function. It currently supports downloading via HTTP, HTTPS, and FTP protocols tar = saves many files together into a single tape or disc archive and can restore individual files from that archive

yum = (Yellow-dog Updated, Modified), is a package-management system that simplifies the downloading, installation, and configuration of software packages

SHORTCUTS / HANDY TO KNOW type first letter of a file name and then press tab - displays files beginning with that letter Ctrl+C = interrupt (if stuck inside a command you don't want to go on with) q = quit, eg. quit from help if not at the end of a file exit = exit from bash as superuser and resume as normal user combine options, eg. ls -lh is the quicker than ls -l -h which also works wildcards (* all, ? single character, [ ] range) copy and paste from and to the command line: ctrl+shift+c and ctrl+shift+v (because ctrl+c etc is reserved for interrupt)

TERMINOLOGY bash = Bourne Again Shell, a command language interpreter, the most popular linux shell shell = a program which interprets commands (interpreter) command line root = top of the (upside down) tree - arguments or options

REFERENCE 1) Folders section: adapted from [|A guide to files and folders on linux]

[] Beginners Linux Guide http://linuxcommand.org/index.php designed to help people new to the command line