Skip to content

Instantly share code, notes, and snippets.

@mikeclagg
Last active September 13, 2017 21:39
Show Gist options
  • Save mikeclagg/4ef1219e8be15947f425294adedf7aef to your computer and use it in GitHub Desktop.
Save mikeclagg/4ef1219e8be15947f425294adedf7aef to your computer and use it in GitHub Desktop.
#! /bin/bash
#############################################
# TASK 1
#############################################
# HOME directory can be accessed through 2 environment variables on most systems
# $HOME and ~
cd ~
# is the same as, works in Windows too
cd $HOME
# mkdir -p
# Create intermediate directories as required. If this option is not specified,
# the full path prefix of each operand must already exist. On the other hand,
# with this option specified, no error will be reported if a directory given as
# an operand already exists. Intermediate directories are created with
# permission bits of rwxrwxrwx (0777) as modified by the current umask, plus
# write and search permission for the owner.
mkdir -p ./bin
# Change directories (cd) to the one you just made
cd ./bin
#############################################
# TASK 2
#############################################
# Copy (cp) file from directory relative directory
# ie: the directory above
# In the first synopsis form, the cp utility copies the contents of the
# source_file to the target_file. In the second synopsis form, the contents of
# each named source_file is copied to the destination target_directory. The
# names of the files themselves are not changed. If cp detects an attempt to
# copy a file to itself, the copy will fail.
cp ../famous.dat famous.data
mkdir -p datafiles
# Copy the new copy to another filename and directory
cp ./famous.data ./datafiles/famous.backup
# Make a hard link
# The ln utility creates a new directory entry (linked file) which has the same
# modes as the original file. It is useful for maintaining multiple copies of a
# file in many places at once without using up storage for the ``copies'';
# instead, a link ``points'' to the original copy. There are two types of
# links; hard links and symbolic links. How a link ``points'' to a file is one
# of the differences between a hard and symbolic link.
ln ./famous.data ./datafiles/famous.hard
# Make a soft link (-s Create a symbolic link.)
ln -s $HOME/bin/famous.data $HOME/bin/datafiles/famous.soft
#############################################
# TASK 3
#############################################
# pwd - Print Working Directory
pwd
ls -la . datafiles
ls -lL datafiles
# http://linuxcommand.org/lc3_lts0080.php
# d)
ls -lL ./datafiles/*.*{f,u}*
# e)
ls -lL **/*.[[:lower:]]*{t,r}?
@mikeclagg
Copy link
Author

Bracket expansion tells the command line interpreter that you want this command expanded outward based on your criteria

ls -lL **/*.[[:lower:]]*{t,r}?
ls -lL list command with 2 flags
**/ a pattern to match any directory under the current one
*. matches anything any length up until a dot (.) occurs
[[:lower:]] is any lowercase character you could use upper, and other options
* another wildcard for any number or any type of character
{t,r} bracket expansion is the equivalent to typing ls -lL **/*.[[:lower:]]*t?and ls -lL **/*.[[:lower:]]*r?
? is a single character wildcard, which means matches can only have 1 more character in them, or second to last

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment