More useful terminal commands for GNU/Linux
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.
- 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.
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:
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:
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.
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.Advertisement