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.
– to simply rename:
(will move ./nameA to ./nameB)
– to move from/to:
mv positionA sub/dir/positionB
(will move ./posiitonA to ./sub/dir/positionB)
Linux terminal used Bash, correct? I’m not very familiar with it or Linux in general, but I’ve always wondered if one should be very familiar with the language or not, since nowadays even Linux is more UI-oriented and noob-friendly, at least the popular Deb-based distros. And you won’t be required to compile tarballs?
Once I had a beautiful cat which was as long winded as Linux. It died.
Actually, if one watches a Linux user or a coder working within the “long winded” terminal, their hands float like butterflies and arrive at the desired destination long before “clickers.” One guy I knew could write commands that made little sense to our group–he’d be done and say, “Go and do likewise.” If you only had a chance to watch a “real” terminal man–the terminator of the slow point and click.
I haven’t used shutdown for years. I always use the GUI. Command line is so yesterday.