More Basic Commands
mkdir (make directory)
- To create a directory:
mkdir myDir
- To create a directory and also create subdirectories:
mkdir -p dir1/dir2/dir3
rmdir (remove directory)
rmdir myDir
- rmdir only removes the directory if its empty
touch
- creates an empty file with the specified name
touch myFile
ls (some more options for ls)
only shows files with name “myFile”
ls myFile
you can use wildcard characters:
- ? - any one character
- * - any amount of any character(s)
- [ab] - a or b
- [a-z] - characters from a to z
- [!a] - any character except a
ls myF?le
ls myF*
ls myFile[ab]
ls myFile[a-z]
ls myFile[!a]
- not very useful in this case, but you can use these wildcard characters with any command
echo
- repeats the arguments back to you
- use > to send the output to a file (caution: it overwrites the file!)
- use >> to append the output to a file
- > and >> can be used with any command
echo Hello, world!
echo stuff > myFile
echo stuff >> myFile
cat (concatenate)
- outputs contents of a file
- cat -n numbers the lines
cat myFile
cat -n myFile
rm (remove)
- deletes a file (permanentaly! There is no Trash folder in Linux)
- rm -i ask you for confirmation before deleting
- Tip: always use rm -i so you don't accidentaly delete anything
- rm -r deletes a directory (including its contents)
- you can combine the options. You can do this for any command
rm myFile
rm -i myFile
rm -r myDir
rm -ir myDir
cp (copy)
- copy a file
- 1st argument is source file, 2nd is destination file
- if destination file exists, cp will overwrite it
- if it doesn't, cp will create it
- cp -i asks for confirmation before overwriting
- always use cp -i
cp myFile myCopiedFile
cp -i myFile myNewFile
cp -r myFile myNewFile
cp myFile otherDir/overHere/myCopiedFile
mv (move)
- mv can move or rename file
- the first argument is the source file, the second argument is the destination file
- if destination file already exists, mv will overwrite it
- if it doesn't exist, mv will create it
- if the destination file name is different, you renamed the file, if its the same, you moved the file
- this is since filename and location are the same in Linux
- mv -i asks for confirmation before overwriting
- always use mv -i
- you can also move directories
- if the source is a file, and destination is a directory, the file gets moved into the destination directory and retains its name
mv myFile myNewFile
mv -i myFile myNewFile
mv myFile myDir/myNewFile
mv myFile ../myNewFile
mv myDir1 myDir2/
mv myFile myDir/
tree
- displays contents of current directory recursively like a tree
tree