Hack Like a Pro: Linux Basics for the Aspiring Hacker, Part 3 (Managing Directories & Files) « Null Byte :: WonderHowTo

Welcome back, my tenderfoot hackers!This is the third installment of my series on basic Linux skills that every hacker should know. Although some hacking tools are available for Windows and Mac, every real hacker uses Linux—for good reason.Make sure to check outPart 1andPart 2of this series before continuing.In this installment, we'll look at how to manage files and directories in Linux, namely copying, renaming, moving, and viewing. Then we'll look a bit at networking and the ifconfig command.Step 1: Copying Files (Cp)Inmy previous installment in this series, we created a file callednewfilein the/pentest/wireless/aircrack-ngdirectory.Let's imagine that we need a copy of the file in our home directory,user root. We can do that by:bt > cp newfile /rootWe simply tell Linux copy (cp) thenewfile(in our current directory) to the directory of theroot user(once again, don't confuse this with the/directory). We don't need to specify the directory that newfile is in, if it's in our current working directory. The copy command makes a copy of the file specified and places it in the specified directory leaving the original untouched and unchanged, so we now have two copies of the original file.You can see in the screenshot above that when we change directory (cd) to theroot userand list the files (ls) that now anewfile copyappears in that directory.What if we wanted to copy a file from a directory that wasn't in our current working directory? In that case, we would need to specify a path to the directory, such as:bt > cp /etc/newfile /rootAlso, note that we don't need to specify the file name we're copying it to. It simply makes a copy and gives it the same name as the original "newfile."Step 2: Moving Files (Mv)Unfortunately, Linux doesn't have a rename command for renaming files, so most users use the move (mv) command to both move files and rename them. Let's imagine now that we placed thatnewfilein the wrong directory and we really wanted it in theroot (/)directory. We can use the move command to do so.bt > mv /root/newfile /This command says, move thenewfilefrom theroot userdirectory to theroot (/)directory. The move command literally moves the file and does not leave a copy where the old one existed. Note that thenewfilehas moved to theroot directory.Sometimes, we want change the name of the file and not actually move it to a different location. The move command can be used for that also. We simply tell Linux to move the original file to a new file with a new name. Take for instance ournewfilein theaircrack-ng directory. Let's say that we want to rename that file to "crackedpasswords. We can simply type:bt > mv newfile crackedpasswordsNotice here that I did not use any directory paths because I was moving a file in my current working directory and to a file in my current working directory. If we run a directory listing now, we can see thatnewfileis gone andcrackedpasswordsnow exists in theaircrack-ng directory.Step 3: Viewing Files (Cat, More, Less)From the command line in the terminal, we can view the contents of files by using thecatcommand.catis short for concatenate, which is a $20 word for putting together a bunch of pieces (we are putting together the words for display on the screen). Concatenate is a fancy word, but is used throughout computer science and information technology, so add it to your vocabulary.Staying in the/pentest/wireless/aircrack-ng directory, let'scatsome files. First, let's get a listing of files in this directory.Notice in the screenshot above, there is a file calledREADME. Often, software developers use this file to provide important notes to their users. This file can be critical, especially with hacking tools because most are open source and seldom have manuals. Let's take a look at the contents of this file.bt > cat READMEWhen you run this command, you'll see lots of text running across your screen. Obviously, it goes by way too fast to read, but when its done, we could use the scroll button on the terminal to scroll up to read all the text. There is another way, though, that might be easier.There are two commands that work similar tocatbut don't simply run the text across the screen until it hits the end of file. These aremoreandless. They are very similar, each only displaying one page of information on your screen until you prompt it to scroll down. Let's trymorefirst.bt > more READMEAs you can see, when I usemoreand thefilename, it displays the file until the screen fills and waits for further instructions from me. If I hitenter, it will scroll down one line at a time, while if I hit thespacebar, it will scroll one page at a time.Now let's try the more powerfulless(in some Linux circles, there is a saying "less is more", meaning that less is more powerful than more).bt > less READMEYou can see thatlessfollowed by thefilename, once again displays theREADMEfile until it fills up my terminal just likemore. Though, note thatlessdisplays the name of the file that I'm viewing in the lower left-hand corner. Probably more importantly,lesshas powerful text searching capabilities that are missing frommore. I can search for text within this file by typing theforward slashfollowed by what I'm searching for andlesswill find it and highlight it for me.That's one of the primary reasons I preferless.Step 4: Networking (Ifconfig)Before I finish this tutorial, I want to show you one last simple networking command,ifconfig. Those of you comfortable with Windows networking, know that you can use theipconfigcommand in Windows to display key information on your networking configuration.ifconfigin Linux is very similar, with only one letter different. Let's runifconfigsee what it tells us.bt >ifconfigAs you can see, it displays much of the key info I need to know about the network configuration of my system including IP address, netmask, broadcast address, interfaces, MAC address of my interface, etc. We'll spend some more time with networking in future Linux tutorials.If you haven't already, make sure to check outPart 1andPart 2of this series, and if you have any questions, ask away in the comments below or hit up theNull Byte forumfor more help.Penguin photoby Matt Biddulph,Linux photoby Black_ClawWant to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 1 (Getting Started)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 2 (Creating Directories & Files)News:How to Study for the White Hat Hacker Associate Certification (CWA)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 21 (GRUB Bootloader)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 9 (Managing Environmental Variables)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 13 (Mounting Drives & Devices)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 11 (Apache Web Servers)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 4 (Finding Files)Hack Like a Pro:Windows CMD Remote Commands for the Aspiring Hacker, Part 1Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 12 (Loadable Kernel Modules)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 5 (Installing New Software)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 16 (Stdin, Stdout, & Stderror)How To:Linux Basics for the Aspiring Hacker: Using Start-Up ScriptsHow To:The Essential Skills to Becoming a Master HackerHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 6 (Networking Basics)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 22 (Samba)How To:Linux Basics for the Aspiring Hacker: Configuring ApacheHow To:Simplify Payload Creation with MSFPC (MSFvenom Payload Creator)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 20 (Devices Files)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 17 (Client DNS)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 7 (Managing Permissions)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 19 (Linking Files)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 25 (Inetd, the Super Daemon)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 23 (Logging)How To:Hack a Site Knowing a Bit of HTML (hackthissite.org) Part 3Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 10 (Manipulating Text)Goodnight Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 8 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 10 - Legal Hacker TrainingNews:First Steps of Compiling a Program in LinuxGoodnight Byte:HackThisSite Walkthrough, Part 7 - Legal HackerCommunity Byte:HackThisSite Walkthrough, Part 10 - Legal Hacker TrainingHow To:Recover Deleted Files in LinuxHow To:How Hackers Take Your Encrypted Passwords & Crack ThemCommunity Byte:HackThisSite Walkthrough, Part 8 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingHow To:Hack Wireless Router Passwords & Networks Using HydraHow To:Use Cygwin to Run Linux Apps on WindowsHow To:Customize Your Linux DesktopHow To:Install "Incompatible" Firefox Add-Ons After Upgrading to the New Firefox