I read an article about command-line recently and one sentence stood out: “many people younger
than 30 have never used, or have little knowledge of command-line”. I would say
that this has some truth to it. As a university student studying Computer
Forensics BSc, I see many people aged between 18-25 and I’ve yet to meet one
who knows the first thing about command-line.
In this post, we’ll be looking at the terminal/*nix shell. In Windows, Mac OS and Linux,
users can communicate with the computer via the terminal. Terminals serve as
conduits for inputting and displaying characters. In Windows, you will see the
terminal referred to as the command prompt, which can be called up by typing
‘cmd’ (without quotes) into Start > Run and hitting enter.
In Mac & Linux, you’ll see a ‘Terminal’ with
an icon like this:
Often, you’ll find that Unix commands don’t carry out an entire task by themselves, but when used
in conjunction with other commands, the usefulness vastly increases. For the following
examples, we wont be using anything Windows-related.
Open up your shell and navigate over to your desktop using the cd command. (cd = change directory) Example: “cd /home/username/desktop”
Now think about what files you may have there. If
you’re anything like me, you probably have a few folders and other files lying
around. If you type in: ‘ls’ you will be presented with a list of files on your
desktop.
That’s OK, but there’s not a whole lot of information there.
Typing in ‘ls –l’ will give you a long-list, which will say: ‘Total x’ where total indicates the total number of disk blocks
required to store the files.
Column 1 displays permissions,
Column 2 displays
links, which we’ll discuss another time,
Column 3 displays the owner,
Column 4
displays the group,
Column 5 displays the size (in bytes) e.g 33964250.
Column 6 displays the
last modification e.g 10 Dec 10:00
and finally Column 7 displays the file name.
You may notice that the results displayed aren’t in
alphabetical order. This may be because you have a mixture of uppercase &
lowercase file names. This is an instance where we need to use two tools
(commands). We will end this post by discussing the pipe symbol: | . The pipe symbol simply lets you transfer
the results over to another command.
So lets say you have just ran ‘ls –l’ but you wish to
sort the results. You could run the following: ‘ls –l | sort’.
Your results
will still be off. If you consult the manual for sort by typing in ‘sort
--help’ you’ll see you need to add –f to ignore upper/lowercase. So typing in:
‘ls –l | sort –f’ will work.
You’re essentially asking for a long list of file
names, permissions, groups, then piping the results of that command over to
sort, ignoring the case. The output will be posted on your screen.
I hope this was a useful insight into command-line for
beginners.
Stay tuned for much more.
No comments:
Post a Comment