Linux User Group, Thapar University
29 February 2016
A terminal or a command prompt is a character based interface to the OS.
All it does, literally, is execute the program you tell it to.
Some commands require superuser (admin) priviledges.
For that we use sudo.
xkcd.com
Different Linux distros have different desktop environments and different terminal shells
E.G. - bash, ksh, zsh, tcsh
Most terminal shells support automatic completion of commands, options and filenames.
This is activated by single or double press of <Tab> key.
The pipe operator '|' is used to redirect the output of one command to the next (left-to-right).
Redirection operators < and > can be used to read from or write to a file.
Operators << and >> are used to read from or append to a file.
$ pwd
/home/seekerThe 'pwd' command tells your location in the filesystem
The 'ls' command lists the files and folders in the present working directory
The 'cd' command lets you change your location
$ pwd
/home/seeker
$ cd Documents/
$ pwd
/home/seeker/Documents
$ cd ..
$ pwd
/home/seekerIn order to print file to terminal, we use 'cat'.
To scroll through big files, use 'less'.
To exit the program, press q.
In order to move a file we use 'mv'. It can also be used to rename the file.
'cp' is used to copy a file.
$ mv soup.py Documents/wolololo.py$ cp soup.py Documents/wolololo.py'mkdir' creates a folder.
$ mkdir Documents/test'rm' can delete a file.
'rmdir' can delete an empty directory.
$ rm soup.py$ rmdir test'rm -r' deletes the directory and everything in it.
$ rm -r testIn order to edit a file in terminal we can use 'vi' editor
A simpler and lightweight alternative is 'nano'
'diff' is used to compare two files for differences.
'file' is used to ascertain type of file.
'man' opens documentation on usage of programs.
'man -k' searches for all available commands.
parameter '--help' shows basic usage information.
'grep' is a powerful string searching utility.
'wc' is used to generate statistics about strings.
'nl' is used to number lines.
'find' is used to search for files in real time.
'locate' is used to search for indexed files.
Redirection: pipe operator '|', <, >, <<, >>
Current location: pwd
List files: ls , tree
Change directory: cd
Open text based file: cat, less
Edit text based file: nano, vi/vim
Usage help: man, --help, info
String searching: grep, strings
File searching: locate, find
Root privilege access: sudo
'ps' is used to list the processes attached to that shell.
'ps -A' is used to list all processes running on the machine.
'kill' is used to terminate a background process.
ctrl+c is used to terminate the foreground process.
ctrl+z is used to suspend a process.
Appending & executes a command as a background process.
'jobs', 'bg' and 'fg' can help manage background processes.
Linux's way of managing permissions etc.
A file in linux has three kinds of permissions associated with it: read, write and execute.
$ chmod 764 scraper.shThe command 'chmod' allows us to edit the permissions of a file, also called modes.
| Owner | Group | Other | |
|---|---|---|---|
| Read | Y | Y | Y |
| Write | Y | Y | N |
| Execute | Y | N | N |
| Numeric: | 7 | 6 | 4 |
$ chmod 764 scraper.sh
$ chmod +ux scraper.shLinux distros come with package managers.
Software for linux often need to be processed using 'make' to install it.
E.G.- apt-get (dpkg), pacman, yum
List processes: ps
Terminate processes: kill, kill -2, kill -9
Manage background jobs: jobs, bg, fg
Run as background process: &
Edit file permissions: chmod +-augorwx
Keyboard Shortcuts:
| Ctrl-C | Terminate foreground process safely |
| Ctrl-Z | Suspend foreground process |
| Ctrl-D | Close current shell |
| Ctrl-L | Clear shell buffer |
The best way to learn about linux is to explore, use creativity to create hacks for whatever you wanna do (hacks are the norm in linux) and to google (or duckduckgo) for whatever you want to do.
Where to start?
This free Introductory course by Linux Foundation on edx.org can get you started. FYI, the course is much more detailed than these slides.
$ ./a.out