Searching in files and using Pipes Flashcards
To look for text within a file use this command:
grep ex: grep pattern file (pattern is what you are looking for in the file)
grep options are:
- i Perform a search, ignoring case
- c Count the number of occurrences in a file
- n Precede output with line numbers
- v Invert Match. Print lines that don’t match
Searching files using some of the following commands. Also you can chain them together to do something really useful
grep pattern file , ex: grep -i User files.txt
file file_name , shows you the file type, ex: file sales.data
strings, lets you see text that’s in a binary format
cut, allows you to cut out portions of a file / ex: cut -d’ ‘ -f2
cut options:
-d delimeter / use as a field separator
-f N displays the ninth field
tr or translate (changes output to something else) ex: tr “:” “ “
column / ex: column -t ( puts output in a table format)
more
less
or the pipe command allows you to tie 2 command together, ex: cat files.txt | more ( you can chain as many command together as you want )
If you want to copy files from your desktop to a linux server or from server to server you would use these commands:
“Are also part of the Secure Shell Protocol”
scp - Secure Copy
sftp - SSH file transfer protocol
Examples of Command line SCP Clients include:
scp
sftp
Putty Secure Copy Client - pscp.exe
Putty Secure File Transfer client - psftp.exe
Some Graphical SCP/SFTP Clients include:
Cyberduck - Mac / Windows
FileZilla - Mac / Windows / and Linux
WinsSCP - Windows only
To customize your Shell Prompt, use an:
Environment Variable
Bash, ksh, and sh use $PS
Csh, tcsh, and zsh use $prompt
Customizing the Shell Prompt with Bash (most popular) PS1:
For a complete listing of all the formatting option, see the “bash” man page
\d - Dante in “Weekday Month Date” format ( TueMay26 )
\h - Hostname up to the first period
\H - Hostname
\n - Newline
\t - Current time in 24 hour HH:MM:SS format
\T - Current time in 12 hour HH:MM:SS format
To make the changes persist between logins, use this Environment variable in your dot files;
“ You can also use Nano, Vi, or emacs to edit this file”
$ echo ‘export PS1=” [ \u@\h \w] $ “ ‘»_space; ~/ .bash_proflie
Aliases are mainly used for:
Shortcuts
Use for long commands
Commands you type often
To view the list of alias’s already set, use this command
alias
aliases can also fix typos:
Make Linux behave like another OS:
$ alias grpe=’grep’
$ alias cls=’clear’
To remove Aliases:
unalias name / Remove the “name” alias
unalias -a / Remove all aliases
So your aliases persist / continue:
Add them to your .dot files
.bash_profile