You are on page 1of 4

The Linux Bash Shell A few shell commands Time [command] - tells you how long the system

took to execute the [command] command pwd shows current working directory Set - various options for the Linux shell. Use this command to customize the shell. Running Programs exec myproc - Exec is used to execute a command when you want the program to replace the shell process. When the program terminates it will terminate the shell. Normally running a program by calling its location will start another process along the shell. ./program - will run the program named "program" inside of your current working directory (. means current working directory) To run the program "program" located in /home/user/ type /home/user/program this will execute the program (. only executes if your in the working directory your current in). You can execute a program just by typing the programs complete path inside of the shell. /home/user/program Note: Program will only run if it's marked as executable with permissions Shell Short Cuts: crtl + R - in shell allows you to search .history file. (pressing repeatedly will keep searching till you find the command your looking for) crtl + P - Does the same as the up arrow crtl + N - does the same as the down arrow crtl + G terminates the search function (escape does the same thing) Crtl + S - Searchs forward in the command history. crtl + A - Move cursor to start of line crtl + E - Move cursor to end of line crtl +B - move backward within a line crtl + F - move forward within a line crtl +D - deletes characters and moves down the line crtl + K - deletes the entire line crtl + X + backspace - deletes all characters from cursors current position back crtl + T - transpose text moves character down the li ESC then c will convert the letter above the cursor to upper case

ESC then u will convert the entire word to uppercase esc history c will clear all of your history. Good for if your trying to hide command line passwords enetered.

Shell Customization and Configuration Each user home directory contains .bashrc and .profile as the main configuration files in bash /etc/profile and /etc/bash.bashrc are the global customizations for all user shells Environment Variables Set environment variables at the command line by typing $: export VARIABLE=whatever View all environment variables by typing env at the command line To delete an environment variable use unset variable name (without $) Redirection Operators Allows you to manipulate standard output and standard error to different files. <> - Specified file will be used for standard input and standard output << - Takes text as standard input Red &> Creates a new file (or overwrites existing) for both standard output AND standard error. 2>> - appends standard error to an already existing file if the file does not exist it is created. 2> - creates or overwrites a file to append standard error. >>Appends standard output to a file or creates the file if it does not currently exist. > creates a new file or overwrites an existing file for standard output clue: 2 represents standard error Data Pipes: A pipe will redirect the first programs standard output to the second programs standard input. This is used by using the | bar. Programs For Manipulating text

Tee - read from standard input and write to standard output and files Example: program | tee file.txt Xargs - build and execute command lines from standard input Example: ls | grep test | xargs rm Will remove all files named test in the folder. ` - backtick works similar to the xargs command Combine files with cat by typing: cat file1.txt file2.txt > newfile.txt Cat is a tool for combining files specifically and is short for the word concatenate Cat n will number the lines of a file Joining Files - join: join lines of two files on a common field -t char use CHAR as input and output field separator. -1 FIELD join on this FIELD of file 1 -2 FIELD join on this FIELD of file 2. -i will ignore case when using the join command Paste - merge lines of files expand - convert tabs to spaces od - dump files in octal and other formats sort - sort lines of text files - By default the sort command uses the first field. You can use k option separated by commas to change what field it sorts on split - split a file into pieces example: split l 2 file1.txt name results in splitting the file every two lines and placing them in namea nameb namec for number of lines by 2. TR -Translate, squeeze, and/or delete characters from standard input, writing to standard output. Example: tr test blah < test this translates all the words of test to blah in the file. Note the < which sends contents of the file to standard input. unexpand - convert spaces to tabs uniq - report or omit repeated lines example: cat test | uniq

FILE FORMATTING COMMANDS Fmt - simple optimal text formatter nl - number lines of files VIEWING FILES Head - output the first part of files, echos first 10 lines of the file. -c to specify the number of bytes to view -n to specify the number of lines to view. tail - output the last part of files less is used to page through files. Most man pages are launched with less and you can use less to launch and view files. It is not used for editing just viewing. The same commands of VI apply to less. Cut - Print selected parts of lines from each FILE to standard output. -c cuts specified list of characters from input file wc word count of a selected file. Sed - is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is seds ability to filter text in a pipeline which particularly distinguishes it from other types of editors. $FCEDIT AND $EDITOR are environment variables that define the default text editors.

You might also like