home |  avr microcontroller & DIY electronics |  toolbox |  science club |  tuxtalk |  photos |  e-cards |  online-shop


some easy and useful linux commands




cd

The cd command is used to change to another directory.

cd ..

gets you one directory higher up.


ls

lists all the files of the directory you are in

ls b*

lists all files in the directory that start with b

ls *sun*

lists all files in the directory that contain the string sun anywhere. However it won't find a string that contains Sun or sUn for example.

ls | grep -i ray

lists all files that include the string ray no matter if the individual letters are upper or lower case. That's very important if you search for a file and only remember that it contains a certain string but not how it was written.

ls -l *mars*

shows you all files in your directory that contain the string mars with additional information. The output will show the permission rights, the size of the file, the last modified date and the name of the file.

ls -l

lists all files in the current directory in a long form with more informations (permission rights, the size of the file, the last modified date and the name of the file).

ls -lx

like above but sorted alphabetically.

ls -lS

The S needs to be a capital letter. This lists all files in long form from biggest to smallest.

ls -lt

lists all files in the current directory sorted by time, that is the files that were last modified are on top.

ls -lrt

lists all files in the current directory sorted by time but as we put the r the order is reversed and the newest file, the file modifed last, is printed at the end.


cp file1 file2

The cp command is used to copy a file. Here file1 is copied into file2.

cp file1 stories/adventure/file2

If file2 is in a different directory you need to specify the path to get there. Here the new file2 is saved under stories/adventure. You need to specify the relative path to get there. So it might be necessary to use ../../ or whatever relative path is needed to get there.

cp ../../stories/adventure/file2 .

If you are in the directory where you need the new file you can also use the command above with the path as needed. The . tells linux to copy the file in the directory you are in right now.


cp -prnv dira pathtodestinationdirectory

If you want to copy a directory into another directory and keep all the subdirectories and files in it intact in the copy you go to the directory where the directory is, that is you go to the source directory. Let's say you want to copy directory dira which is in directory dirup. Then you go to directory dirup. There you type the above command and you are done.


diff file1 file2

This command is used to see if the content of 2 files is the same or what the differences are. If they are the same there is no output, otherwise the differences are listed.


mv file1 file2

mv stands for move and the command is used to rename a file. Here file1 will disappear and instead now be named file2.


ps auxw | grep fire
kill -9 1234

with 1234 being the process ID of firefox (in this case). If your firefox has crashed once again and is hanging you first type the first command to get the process id. Then you type the second replacing 1234 with the actual ID. After that you can restart firefox. To use this command for any other application just replace fire with the appropriate name.


mkdir newfilename

to create a new directory


rm

remove (delete) a file

rmdir

remove (delete) an empty directory


find . -type f | grep -i andromeda

This command looks for files, not directories that contain the string andromeda, the -i makes it case insensitive

find . -type f | grep -i andromeda | grep -v Documents

This command looks for files, not directories that contain the string andromeda, the -i makes it case insensitive, the addition | grep -v Documents excludes the results that contain the string Documents

find . -mtime -2

You can use the above command if you are looking for a file that you know you have modified within the last 2 days. Of course you could change the 2 into 1 or 5 for example to get the files you changed within the last day or the last 5 days respectively.

find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r

You can use the above command if you are looking for a file that you know you have recently modified. The command lists all files in the current directory ordered such that the most recently modified files are shown first.


date

Type date on the shell and you get the current date, starting with the day of the week, followed by the month, the day of the month, the time and the year.


cal

Just typing cal returns the calendar for the current month.

cal 2022

This returns the full calendar for the whole year.

cal 8 2021

returns the calendar for August 2021.

cal aug 2021

also returns the calendar for August 2021. You can also write August. It's not case sensitive. And the program only looks at the first 3 letters.

cal -m 5

This returns the month, in this case May of the current year.


top

This gives you information on the cpu load and memory usage of the processes running on your computer sorted by cpu load. You can quit by typing q.








Copyright © 2004-2024 Katja Socher, tuxgraphics.org