mkdir test
mkdir -p test/test1
mkdir [options] <Directory>
. Make a directory. Option is for adding other paths.
mkdir -p
Tells mkdir to make parent directories if needed. So mkdir -p test/test1
is to create a test directory in the current directory if it does not exist and create another test1 directory nested within test1.rmdir test/test1
rmdir [options] <Directory>
. For this command, the directory must be empty before it may be removed. So now the test directory will be empty. Be careful with the remove command line, since it can not be undone. Once you’ve removed it, it’s a gonner.
cd test
mkdir foo
touch example1
touch [options] <filename>
Create a blank file named example1.
cp example1 barney
cp -r foo foo1
cp [options] <source> <destination>
. Copy a file or directory. Copies the example1 file and name it barney. Note that both source and destination can be paths. When using cp
, the destination can be a path to either a file or directory.
cp
will only copy a file. Using the -r
option, which stands for recursive, we may copy directories. Any files and directories sitting within the directory foo will also be copied to foo1.mkdir backups
mv foo1 backups/foo2
mv barney backups/
mv [options] <source> <destination>
. Moving the file. The line above means that :
The example above shows that mv
can be used to change names of a file. Now if we specify the destination to be the same directory as the source, but with a different name, then we have effectively used mv
to rename a file or directory.
rm example1
rm -r backups
rm [options] <file>
. Remove a file.
-r
, same which cp
is stands for recursive. When you run rm -r
it will remove the directories and all files and directories contained within.Wildcards are a set of building blocks that allow you to create a pattern defining a set of files or directories. The basic set :
*
Represents zero or more characters.?
Represents a single character.[]
Represents a range of characters.touch barry.txt
touch blah.txt
ls b*
ls *.txt
The command line create two .txt file name barry and blah.
ls b*
is listing every file beginning with a b.ls *.txt
is listing every .txt type file , regardless of their file name.ls *.???
List every file with a three letter file type.
ls [fb]*
ls [^f]*
The range operator allows you to limit to a subset of characters. So
ls [fb]*
here will look for every file whose name either begins with a f or b.^
caret symbol in the front indicates do not match. ls [^f]*
matches any file that does not begin with a f.