Examples of Bash Shell Features.md
whoami
id
uname -a
man top
man
pages, including a brief description for each command:man -k .
curl --help
date
ls -lrt
.sh
:find -name \'\*.sh\'
pwd
mkdir new_folder
> Up one level:
cd ../
> To home:
cd ~` or `cd
> To some other directory: cd path_to_directory
rmdir temp_directory -v
ps
ps -e
top
df
touch a_new_file.txt
cp file.txt new_path/new_name.txt
mv this_file.txt that_path/that_file.txt
rm this_old_file.txt -v
chmod +x my_script.sh
chmod u+x my_file.txt
chmod go-r
cat my_shell_script.sh
more ReadMe.txt
head -10 data_table.csv
tail -10 data_table.csv
echo "I am not a robot"
echo "I am $USERNAME"
sort text_file.txt
> ##### In reverse order:
sort -r text_file.txt
uniq list_with_duplicated_lines.txt
> Lines:
wc -l table_of_data.csv
> Words:
wc -w my_essay.txt
> Characters:
wc -m some_document.txt
Some frequently used options for grep
:
Option | Description |
---|---|
-n |
Print line numbers along with matching lines |
-c |
Get the count of matching lines |
-i |
Ignore the case of the text while matching |
-v |
Print all lines which do not contain the pattern |
-w |
Match only if the pattern matches whole words |
grep -iw hello a_bunch_of_hellos.txt
.txt
:grep -l hello *.txt
Suppose you have three files containing the first and last names of your customers, plus their phone numbers.
paste
to align file contents into a Tab-delimited table, one row for each customer:paste first_name.txt last_name.text phone_number.txt
paste -d "," first_name.txt last_name.text phone_number.txt
cut
command to extract a column from a table-like file:Suppose you have a text file whos rows consist of first and last names of customers, delimited by a comma.
cut -d "," -f 1 names.csv
cut -b 2-5 my_text_file.txt
cut -b 10- my_text_file.txt
tar -cvf my_archive.tar.gz file1 file2 file3
zip my_zipped_files.zip file1 file2
zip my_zipped_folders.zip directory1 directory2
unzip my_zipped_file.zip
unzip my_zipped_file.zip -d extract_to_this_direcory
hostname
ping www.google.com
ifconfig
ip
curl <url>
wget <url>
Jeff Grossman
Sam Propupchuk