Jump to content

25 Linux Commands and Tricks That Every Geek Should Know.


Jaaa!&

Recommended Posts

 

1. Log Into a Linux Machine Without Knowing the Username or Password

If you come across a Linux machine that you need to gain access to but you don't know the username or password, you can gain access by following these steps:

 

Restart the system and press 'e' or F2 to enter GRUB menu. Choose 'ROOT' in the options. In the command line that appears, type 'tail /etc/passwd' and locate the username in the text that appears. Now that you have that username, type 'passwd USERNAME' and enter a new password. Once finished, type EXIT, select OK to exit recovery mode, and then login with the username and new password.

 

 

2. Combining TXT files

If you have two text files with lines that are identified as below, you can join them with the following three commands. Be sure the lines match, however, and put them in the order you want the files combined.

 

$ cat animals.txt

 

100 Dogs

 

200 Cats

 

300 Lions

 

$ cat actions.txt

 

100 bark

 

200 meow

 

300 roar

 

$ join animals.txt actions.txt

 

100 Dogs bark

 

200 Cats meow

 

300 Lions roar

 

 

3. Check Out How Many Hours a Computer Has Been On

Find a system's up-time with this piece of code. The numbers given will be listed as hours. So, for example, if it says 9.32, the system has been up for 9 hours and 32 minutes.

 

$ ac –d

 

 

4. View All Running Processes

Linux doesn't have a task manager like you find in Windows. While you can download various types online, the best way to view the current running processes on your system is to open the terminal and run:

 

$ ps aux | more

 

 

5. Check On Total Disc Space Usage of A Directory+ Its Subs

If you're low on disc space and you want to find out which of your directories are taking up the most space, then you can use the following command. Replace the home symbol ( ~ ) with whatever directory you want to check. For example, du -sh /etc.

 

# du -sh ~

 

 

6. View Active Network Connections with PID

Take a peek to see what connections are currently active on the network with this handy command.

 

# netstat -tap

 

 

7. Find All Files on a System Larger than X MB/GB

Say you just downloaded a 1GB+ ISO onto your system, you know it is around somewhere, but you just can't figure out where it was saved. This little bit of code is a nifty solution for locating the file.

 

# find / -type f -size +1000M

 

 

8. Locate and Identify Recently Altered Files

Do you want a nice list of files that have recently been altered on any given system? If so, enter this tidbit into the terminal:

 

# find . –mtime -2

 

 

9. Find a Past Date

Say you need to find out rather quickly what the date was 49 days ago. To find out, type:

 

$ date --date='49 days ago'

 

 

10. Find a Future Date

In the same vein as the previous example, say you need to find out what the date will be in 49. To find that out, type:

 

$ date --date='3 seconds'

 

Note that it's the same as the last bit, only without the word 'ago' added.

 

 

11. Locate Files with Specific Words in the Name

If you need to find a file on a system that has a specific name, such as 'passwords' or 'taxes', then you can search a directory with the following code:

 

# find ~ -name "*passwords*"

 

 

12. View Processes Run By Different Users

If you want to see what processes are running for different users that the one logged in, run this:

 

$ ps U oracle

 

 

13. View Items Inside Compressed (Archive) Folder

Have you ever downloaded an archive, only to discover junk inside it? The following command will reveal what is inside a zip folder before you open it.

 

# unzip -l var-name.zip

 

 

14: Eject Removable Media

Where it's an iPod or an SD card, you can eject onboard media by simply typing:

 

EJECT

 

 

15: Save the Active Window as a JPEG

If you need to save the active window on your desktop as a JPEG but don't want to download any special software or use PrntScrn and a photo editor, use this command:

 

import -window root MyTest.jpg

 

 

16: Bump User Off Network

Whether they're doing something that is going to contaminate the network, they're hogging resources, or you simply don't like them, you can log a user off their computer with this handy piece of code:

 

skill -kill -u username

 

 

17. Block a Computer's Access to Specific Websites

Say you're running a business that uses Linux machines, you notice that your employees are spending a ridiculous amount of time checking the weather. You can block their ability to access those sites by opening /etc/hosts with your text editor (sudo gedit /etc/hosts) and adding:

 

127.0.0.1 website.com

 

 

18. Schedule Midnight Downloads

This code is incredibly handy; it allows you to schedule the time for a download to happen--say, at 3PM while you're at work or midnight while you're sleeping.

 

echo 'wget website.com' | at 012:00

 

 

19. Using the Terminal As Root

Using the Terminal as root is sort of like right-clicking on an application in Vista and choosing 'run as Administrator'. It gives you the ability to do things you otherwise couldn't do (namely, run dangerous code). To use the terminal as root, type:

 

sudo su

 

 

20. Disabling Password Prompt When Using Sudo

Whenever you use the 'sudo' command in Linux, you're prompted to enter the user password before the command will go through. This gets annoying. The solution? Disable it. To do so, use the Terminal and type:

 

gedit sudo visudo

 

scroll down to the line that says: username ALL=(ALL) ALL

 

and change it to say: username ALL=(ALL) NOPASSWD: ALL

 

 

21. Change the Default Conky

If you're using a distro that includes Conky by default, such as Crunchbang, you might wander how you can edit its settings. To do this, enter this in the Terminal:

 

sudo gedit ~/.conkyrc

 

Of course, replace 'gedit' with the text editor of your choice, and sudo is Ubuntu specific.

 

 

22. Put a LiveCD on a USB

Say there's a machine you want to gain access to and copy files from, but you don't have access to the computer's login info. You can gain access with it using a LiveCD. The easiest way to do this is by using a USB thumb drive. You can do this by downloading a liveCD iso and then downloading UNETbootin.

 

Plug in your USB drive, run UNETbootin, and install the ISO with that.

 

 

23. Safely Restart Linux

Lets say you're duped into running a fork bomb, or you download a file that promises to be one thing, only to turn out to be a massive tarbomb. How do you safely restart the frozen system? By doing the following:

 

Press ALT + PrntScrn and then, while holding those, type the following letters in order: REISUB.

 

 

24. View All Files (Including the Hidden Ones)

If you need to view all the files within whatever directory you're in, including ones that are hidden, use the following bit of code:

 

ls -al

 

 

25: A Bonus Tip:

Never run the following:

 

:() { :|:& };:

 

...there's something about it that begs to be run; doing so, however, will initiate a forkbomb, which will cause your system to freeze.

 

 

Link to comment
Share on other sites

For number 17, there is two equvialent ways to perform that on other machines. One is to use a routing table on a router; the other, for Windows based computers is the HOSTS file located in %systemroot%\System32\drivers\etc

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.