Know just enough, to not be dangers!
Software Developer, Product Designer, Consultant & Entrepreneur
Really? Why not?
The Bourne-Again Shell
Would you rather have me call it, file management? How boring!
ls | - | Lists the contents of a directory. |
tree | - | List the contents of directories in a tree-like format. |
pwd | - | Feel lost and want to get your bearings? Prints the name and path of the current directory. |
cd | - | Move around and go places by changing directories. |
cd ./path # Go to a sub directory from the current parent directory.
cd ~ # Go to your home directory.
cd / # Go to the root/top of your file system.
cd .. # Go one level above the current directory.
cd ../.. # Go two levels above the current directory
mkdir | - | Create a directory if it doesn't already exists. |
cp | - | Copy source files and directories to a provided destination. |
mv | - | Move or rename files and directories. |
rm | - | Delete files and directories. What ever you do! Never, ever run "rm -rf /" as root. |
touch | - Need a new empty file? Just use touch! |
rm ./file.ext # Delete the given file.
rm -rf ./directoryname # Delete the given directory along with all of it's
# files and sub-directories. Use, with caution.
No easy way in, let's just push through!
ls -l /dev | more
# Insert the given content into a file by overwriting anything in the file, if it already exists.
echo "The quick brown fox jumps over the lazy dog" > readme.txt
# Append and not overwrite the given content to the end of a file, if it already exists.
echo "A phrase that has every letter in the alphabet in it." >> readme.txt
This sounds boring! But wait, it is!
# Display the contents of a file(s).
cat filename.txt
cat filename.txt filename2.txt
# Copy a files content to another file.
cat oldtextfile.txt > newfile.txt
# Similarly, you can concatenate several files into a destination file.
cat filename.txt filename2.txt > newfilename.txt
# Append a files contents to another file.
cat filename.txt >> another-text-filename.txt
cat filename.txt filename2.txt >> another-text-filename.txt
# Add numbers to the output of a file or stream.
ls -la /bin | cat -n
tail -f access.log
# Extract the second IP address from the list.
echo "192.168.1.123 54.192.77.176 192.168.1.111 216.58.212.206" | cut -d' ' -f2
# This will return:
# 54.192.77.176
# Only cut, the first-through-second and fifth-through-sixth field of each line.
# filename.txt
# one two three four five six
# alpha beta gamma delta epsilon zeta
cat filename.txt | cut -d' ' -f 1-2,5-6
# Just give me the fourth field and every filed after that.
cat filename.txt | cut -d' ' -f 4-
# List all usernames on the system.
cut -d: -f1 /etc/passwd
# List all usernames and their home directories with a space in-between them.
cut -d: --output-delimiter=' ' -f1,6 /etc/passwd
sort | - | A simple but useful command to rearrange the contents of a text file or stream, line by line. So that, they are sorted, numerically and alphabetically. |
uniq | - | It reports or filters out repeated lines in a file or stream. Though, it doesn't detect repeated lines unless they are adjacent. For that, you should first use sort. |
In the end, everything is a stream that flows through the universe.
# Find all StackOverflow links from a Markdown file.
grep stackoverflow Reading-List.md
# Find all To Do items in all files under each directory, recursively.
# Along with a line number for each To Do task.
# code.rb
# ---------------------------
# def foo
# # TODO: Test this code.
# 1 + 2
# end
#
# def bar
# # FIX: Divided By 0 Error
# 1 / 0
# end
#
# def baz
# # BUG: Need to fix this.
# raise "SomeBugName"
# end
grep -rni --color 'TODO:' ./
# This performs a case-insensitive grep search and returns:
# ./code.rb:2: # TODO: Test this code.
Long time, no see!
# Get user data from the JSON, User API endpoint of GitHub.
curl https://api.github.com/users/usmanbashir
# Get a list of all followers for the user.
curl https://api.github.com/users/usmanbashir/followers
# Authenticate with the Twilio API using GET HTTP requests.
# Their REST API is protected with HTTP Basic authentication.
curl -G https://api.twilio.com/2010-04-01/Accounts -u '[YOUR ACCOUNT SID]:[YOUR AUTH TOKEN]'
# Send an SMS to a friend.
curl -X POST \
'https://api.twilio.com/2010-04-01/Accounts/AC5ef872f6da5a21de157d80997a64bd33/Messages.json' \
--data-urlencode 'To=+16518675309' \
--data-urlencode 'From=+14158141829' \
--data-urlencode 'Body=Hey dude! Good luck with the exam!' \
-u AC5ef872f6da5a21de157d80997a64bd33:[AuthToken]
# Download a single file from the net.
wget http://example.com/file.zip
# Download a file but save it locally under a different name.
wget ‐‐output-document=filename.zip http://example.com/file.zip
# Resume an interrupted download previously started by Wget itself.
wget ‐‐continue example.com/some_big_file.zip
Though, don't let it, get to your head.
# 1. Retrieve information about the eth1 network interface.
# 2. Filter it down only to the IPv4 line.
# 3. Cut out almost everything else and only leave the bits about the IP address.
# 4. Get the first field, which contains the IP address.
# 5. Get the IP bit for the computer and not the gateway part of it.
ifconfig eth1 | grep "inet addr" | cut -d: -f2 | awk "{print \$1}" | cut -d. -f4
For the love of God, yes please!
man ascii
End? No, the journey doesn't end here.