history 5 of 36
My First Linux Commands: Files, Directories and Users
Early notes on moving, renaming, viewing and deleting files with mv, mkdir, less and rm, plus adding and removing users, with fixes and examples.
Written
From my Linux study notes, 2012. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.
These were some of the first Linux commands I wrote down while learning. My original notes are kept below, with corrections where a command was wrong.
Before you start
- You need a Linux terminal. Practise in a test folder (for example
mkdir ~/practice && cd ~/practice) so you cannot damage important files. - The user commands (
useradd,userdel) must be run as root or withsudo.
My original notes
-
For move file:
Terminal window mv oldfile newfileThe original said
noldfile, which was a typo foroldfile. Note that when the destination is a new name in the same directory, this actually renames the file (Linux has no separate rename command for single files). -
To make new directory:
Terminal window mkdir dirname -
To put file into a new directory:
Terminal window mv textfile dirname/The trailing
/makes it clear thatdirnameis a directory. If the directory does not exist,mvgives an error instead of silently renaming the file. -
To change file name:
Terminal window rm filenameCorrection: this is wrong.
rmdeletes a file, it does not rename it. To change a file name, usemv:Terminal window mv oldname newname -
To view the text file:
Terminal window less filename -
To add new user:
Terminal window useradduseraddneeds a user name, for exampleuseradd username. Run on its own it only prints usage help. -
To del user:
Terminal window userdel username -
lesscommand to see the text file: pressqto quit.
A worked example
Try these in your practice folder:
echo "hello" > notes.txtmkdir archivemv notes.txt old-notes.txtmv old-notes.txt archive/ls archiveless archive/old-notes.txtWhat each line does:
- Creates a small text file called
notes.txt. - Creates a directory called
archive. - Renames
notes.txttoold-notes.txt. - Moves it into
archive. - Lists the contents of
archive, so you can check the move worked. - Opens the file in
less(pressqto quit).
Notes for today
mvoverwrites the destination file without asking if it already exists. Usemv -ito be asked first. The same-ioption works withcpandrm.rmdoes not use a Recycle Bin. Deleted files are gone.rm -i filenameasks for confirmation.cp oldfile newfilecopies a file and keeps the original;mvmoves or renames it.- After
useradd username, set a password withpasswd usernameso the account can log in. On Debian and Ubuntu,adduseris a friendlier interactive alternative. userdel usernamekeeps the user’s home directory.userdel -r usernameremoves the home directory and mail spool as well, so only use it when you are sure.- Useful keys in
less:/wordsearches forward,njumps to the next match,Spacegoes down a page,ggoes to the start andGto the end.