In a previous article we talked about some simple commands for people to learn to do in a Linux terminal like changing directories, or copying files.
Today, I’ll be showing you some more useful things the terminal newbie may or may not know how to do, like renaming files, shutting down and rebooting your machine, or scheduling a shutdown/reboot at a specific time.
How to rename files
Simply put, renaming files isn’t done like it is in other systems, we aren’t really renaming the file, we are going to move the file, giving it a new name in the process. To do this, we need to use the command for moving:
- mv X Y
As discussed in our previous article, mv is the command used to move files from point A to point B. This can be done from within any directory, to any directory, even if you are not currently situated in the director that the file is contained in.
For example
- sudo mv ~/myfile /var/log/someprogram/logfiles/morefolders/myfile2.log
The above command moves the file ‘myfile’ out of the users home directory and places it into a subfolder of the /var/log directory, under the new name ‘myfile2.log’
Note: The sudo preface was used, because you can’t move a file to /var/ without it, sudo is not essential to using the mv command if you remain out of directories that require root access.
Moving a directory is the same idea:
- mv ~/test1 ~/Documents/test2
This command will move the directory ‘test1’ into the Documents folder under the new name ‘test2’, and will not change the names or affect the files within that document, keeping them safely intact.
Read also: Encryption and Strong Passwords
Shutting down and restarting your machine
If you’re using a modern distribution then shutting down and rebooting don’t even need root access (with most distributions) anymore – handy!
Shutting down is as simple as typing:
- shutdown
To which you will receive a message similar to:
Shutdown scheduled for Thu 2017-09-28 11:49:59 EDT, use ‘shutdown -c’ to cancel.
And obviously if you wish to cancel:
- shutdown -c
Rebooting your PC is just as simple:
- reboot
Done!
However….There are more advanced things we can do with these commands…
- shutdown -h XX:XX
This command will automatically shut the machine down at the specified time, in 24-hour format. Replace X with the appropriate numbers, and you are done.
- shutdown -r XX:XX
This will do the same thing, but will reboot the machine at the specified time.
Final words
So there you have a few more neat little tips and tricks for when you’re in a text environment, great for remote servers, or if you’re in a hurry, as I personally find it faster to simply use the various commands, rather than clicking around an interface.