Bash Basics, Part 3: File Manipulation
It's time we give our GUI a break and learn how to move, copy, edit, and delete files through the CLI on Linux.
If Daft Punk's digital age anthem Technologic ever gave you the urge to dive deeper into the technology world, you're in the right place! It's time we give our GUI a break and head over to the almost musical world of the command line. After all, with commands like 'zip', 'unzip', 'copy', and 'touch', you're orchestrating your own "Technologic" symphony right on your keyboard. It's time to upgrade your skills. Let's dive into learning how to move, copy, edit, delete, and add a bit of techno-funk into our everyday computing tasks.
man
command to read the manual for any command on your system. I also highly recommend checking out tldr.sh.mkdir
mkdir
is used to make a directory.
$ mkdir bin/
rmdir
rmdir
is used to remove a directory. Note that the directory will have to be empty for this to work.
$ rmdir bin/
touch
touch
is used to create an empty file or to change the timestamp for an existing file to the current time.
$ touch file.txt
find
find
lets you search for files on the local filesystem and prints the search results.
$ find / -name nginx.conf
nano
nano
is one of the easiest-to-use command-line text editors for Unix-like operating systems.
# nano /etc/fstab
vim
vim
is a more powerful text editor which can be installed on almost all Unix systems. It is known for its extensive features and numerous commands.
$ vim /var/www/index.html
rm
rm
is used to remove files or directories. To remove directories and all their contents, the "-r" (recursive) flag is used.
$ rm file.txt
$ rm -r directory/
mv
mv
is used to move or rename files or directories. It takes two arguments: the current name and the new name or location.
$ mv old-name.txt new-name.txt # renaming
$ mv file.txt new-dir/ # moving
cp
cp
is used to copy files or directories. Like mv
, it takes two arguments: the source and the destination.
$ cp file.txt copy-file.txt
$ cp -r original-dir copied-dir/
ln
ln
is used to create links between files. By default, it creates a hard link, but with the "-s" option, it can create a symbolic (or soft) link. Symbolic links are like shortcuts in Windows.
$ ln file.txt link-file.txt
$ ln -s source-file symbolic-link
zip
zip
is used to compress files into a zip archive.
$ zip archive.zip file.txt
unzip
unzip
is used to extract files from a zip archive.
$ unzip archive.zip
tar
tar
is used to archive files. Many Linux programs come in a "tarball", or a .tar.gz
format. tar
can also be used with other commands to compress files.
$ tar -cvf archive.tar file.txt
$ tar -xvf archive.tar # Whenever you need to extract files from a tar archive
scp
scp
stands for secure copy. It's used to transfer files securely between local and remote systems. Just like cp
, it needs a source and a destination.
$ root@192.168.1.55:/path/to/my/secrets.txt ~/Documents # Copying files from a server
$ scp ~/app.py user@example.com:/opt/myapp # Copying files to a server
These foundational commands will help you navigate the digital world, letting you control your computer in ways you might not have thought possible. But remember, mastering any new skill takes time and practice. So, don't feel discouraged if it doesn't sink in immediately.
I hope this blog post has helped break down the commands into a manageable list. Don't forget that playing around with these commands is the best way to get comfortable. If you haven't already, get started by setting up a Linux environment today!
And with enough practice, you too will soon be Harder, Better, Faster, and Stronger with Linux.