Linux/Mac Terminal Tutorial: Create, Copy, Move, Rename and Delete Files and Directories
Skills:
Tool Use & Function Calling85%
Key Takeaways
This video tutorial demonstrates basic Linux/Mac terminal commands for creating, copying, moving, renaming, and deleting files and directories using tools like MKDIR, CP, MV, RM, and CD.
Full Transcript
hey how's it going everybody in this video we'll be going over some simple terminal commands to get you more comfortable within the command line in a previous video we learned how to navigate the file system without altering the file system in any way uh but in this walkthrough we'll actually be creating files and directories we'll be deleting files and directories and we'll also learn how to copy rename and move files and directories so I'll have my finder window opened on this side of the screen so we can visually get an idea of what's going on uh so let's go ahead and get started so first of all over here in the terminal if I run PWD which stands for print workking directory we can see that I'm currently within my user folder projects demos terminal and Basics now this is also the folder that I'm in over here within finder uh so that we can see what's going on now let's go ahead and create a directory within this folder called tester and the way that we're going to do that is MK IR make dur and we'll call this test dur now you can see when I ran that that this folder popped up over here within finder uh but within the terminal we can run LS and we run LS we can see that the directory is also showing up within terminal so now let's go ahead and navigate to that directory and to do that we do CD test dur and navigate into there and within finder we'll just click into it so now let's create a file within this directory called test file so I'm going to do a touch to create this file and that'll be testor file.txt and if I run that command you can see over here in the finder window that that test file was created now I'm going to go ahead and open this file and add some text so that we have some unique file contents to work with and we can do this within the terminal with open test file.txt and that'll use the default program on your machine to open up this file and the contents that I'm going to add here are just I'm just going to call it test file file uh txt the same name as the file slightly different so now let's go ahead and close that down so now let's learn how we can make a copy of this file within terminal to do this we use the CP command so I'm going to do CP and then to autocomplete like that I'm just hitting tab after I type a little bit so I'm going to do CP testore file.txt and this new file uh I'm just going to call copy file.txt so now if I hit enter there you can see within our finder window that it created this copy file.txt and if I open this up you can see that it does have the same file contents that we put in the first file so it is a copy so now let's look at how we can rename a file now renaming a file might seem a little weird because moving a file and renaming a file is actually the same process so if you want to rename a file then you use the MV command which is the move command and since we're just going to leave it in the same place we're going going to move the file to the same directory but give it a different name so I'm going to rename testor file.txt to uh original file.txt so I'm going to do move test file.txt and I'm going to call this aridor file.txt and you can see when I ran that command we no longer have test file.txt we have this arid file. txt now what if we want to move a file without renaming the file we can do that by specifying a new location and no file name so to show an example of that I'm actually going to create a new directory here in this current folder called subur one so if we remember it's make dur sub dur one and you can see that here within finder now I'm going to move this original file.txt to subor one but I'm not going to rename the file so I can do that just by doing a move orid file.txt and now I'm going to type in the new location and I want to put this within subor one so if I run that you can see that the file vanished over here within finder and within terminal I'm going to CD and subor one and do an LS and you can see that the file's there if I navigate there in finder you can see that it is there also so now I'm going to move it and rename it at the same time so to do this I can just do a move a rid file.txt and I'm going to move this up One Directory into our tester folder fer which is visible over here in finder and now that I've specified the location I'm going to go ahead and give it its name back to file.txt so if I run that command now we can see that this subur one is empty and that the original file got moved back to our tester and renamed at the same time and if I open this up you can see that the contents are still the same okay now let's look at how we can delete some files to delete a file we can use the RM command so let's remove this copied file here with RM copy oh and actually I'm in sub one so let me CD back up a directory so now I'm going to do RM copy file.txt and you can see over here within test dur that the copy file.txt was deleted now be careful when you're running remove files from within the terminal because deleting a file within the terminal isn't the same as deleting a file on your file system it doesn't ask you are you sure and they don't get sent to your trash can for easy recovery so when they're gone they're gone uh so be careful when using the remove files within the terminal now we've been looking at how we can copy and rename and delete files uh now let's look at how we can do some of these same things to directories working with directories can be slightly different than working with files so let's go ahead and move up a directory here so that we can see our entire tester directory so if I do an LS you can see that we have our tester here and I'm I'm going to go ahead and do that over here within finder also so now let's try to copy our tester uh to a directory called copy dur in the same way that we did a file so I'm going to do a CP test dur and then I want to name the copy copy dur so let's run that so the first problem that we run into here is that it says that copy dur doesn't exist so let's go ahead and make a directory called copy dur and run that now you can see that this directory exists but it's empty so now let's try that command again copy the tester into coper now you can see that we're getting this message that tester is a directory not copied so in order to get around this we need to use the- R option now remember if you ever need to find out more about the options that are available to you then you can do that by viewing the man Page by typing man and then the command that you want to look at so if we did man CP then you can look at all the options that you have available to you there you can just hit Q to get out of that so we're going to be using the- R option so really quick let's just take a look at what that means exactly so you can see here this- R it says if the source file designates a directory CP copies the directory and the entire subtree connected at that point so that's what we want so let's go ahead and do that so if I go back to my CP command I'm going to come back here to the beginning and do a dashr so now if I run this and make this half the size of the screen so now we didn't get any errors that time so if we do open this up you can see that it has all of the same contents that tester had so now we successfully copied our entire directory so now let's try to rename the directory remember when we rename the files we use the MV command so let's try to do that to our tester so I'm going to do a move tester and let's rename this to a ridge so if I run that then you can see that we didn't get any errors and that over here within finder it did rename this to aiger so the MV command renamed the directory without needing any additional options and also like files I can move the directory without renaming uh the directory so if I wanted to do an MV of arider I'm going to move this entire directory within the copy dur directory so if I run that then we can see that it took it out of this folder here and if I navigate to coper it still has the other contents that tester used to have but we also have the original directory here and it contains all these contents as well so now lastly just like we did with files let's go ahead and move the directory back up to the Parent Directory and rename it at the same time and we'll rename it back to tester so in order to do this I'm going to CD into the copy D here and that's where we are within finder over here and I'm going to do a move and I'm going to move the original directory up One Directory to the parent and then at the same time I'm going to rename it to tester so if I run that you can see that the original directory is no longer within the copy directory and if I navigate back to the parent folder then it was renamed to tester and you can see that all the subfolders and files are still there so one more thing just like with the files let's go ahead and try to delete a directory so if we remember when we deleted the file we use the RM command so let's do an RM and let's try to delete this copy directory oh and actually I need to navigate up to my parent folder where these two directories are and now let's do an RM and let's remove the copy directory now you can see here that I got this error and just like copying a file it says that copy dur is a directory um so also just like copying we can add the- R option and it will remove the directory so I'm going to do an rm- r on copy dur so now if I run that within finder over here you can see that the copy directory was deleted so one last quick note here sometimes you might run into some files that give you issues when you try to delete them uh if you want you can force a deletion of the directory by using the dash F option now again you do want to be careful with this um now to do this you do RM and then dashr because we are deleting a directory and we're going to do this- F to force the deletion and then I'm just going to delete the tester that we have here and if I run that you can see that it deleted the directory so once again be careful with uh that command because it's very powerful and it will permanently delete your files uh the only way to recover them would be from some kind of backup and that's something that anyone likely wants to do you and also just a reminder there's a ton of other options that you can use with these commands so be sure to check out the Man pages if you ever get stuck and just kind of play around with all the cool things that you can do but uh hopefully you guys found this overview of these commands useful uh keep practicing with these commands um it's really one of those things that you wonder how you lived without it once you begin using these on a regular basis but if you all do have any questions uh feel free to ask in the comment section below be sure to subscribe for future videos and thank you all for watching
Original Description
In this video, we will be learning basic terminal commands which will allow us to create, copy, rename, move, and delete file and directories. These commands include: touch, mkdir, cp, mv, rm, as well as exploring some options we can use with these commands. Let's get started.
✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms
✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join
✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - http://coreyms.com/
My Second Channel - https://www.youtube.com/c/coreymschafer
Facebook - https://www.facebook.com/CoreyMSchafer
Twitter - https://twitter.com/CoreyMSchafer
Instagram - https://www.instagram.com/coreymschafer/
#Linux #Mac
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Corey Schafer · Corey Schafer · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Web fonts using CSS Font Face
Corey Schafer
Using Font Awesome in Desktop Applications (OS X)
Corey Schafer
Sublime Text 2: Setup, Package Control, and Settings
Corey Schafer
ArcGIS API for JavaScript Part 1: Our First Web Map
Corey Schafer
Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Corey Schafer
Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Corey Schafer
ArcGIS API for JavaScript Part 2: Starting Templates
Corey Schafer
Paver Patio Time Lapse
Corey Schafer
Mac Tip: Ways to perform Screen Capturing and Screenshots
Corey Schafer
WordPress Plugins: Imsanity
Corey Schafer
WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
Corey Schafer
Sublime Text 3: Setup, Package Control, and Settings
Corey Schafer
Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Corey Schafer
Mac Tip: Adding Folder Stacks to the Dock
Corey Schafer
CSS Tips and Tricks: Add External URLs to Print Stylesheets
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
Corey Schafer
Python Tutorial: if __name__ == '__main__'
Corey Schafer
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Corey Schafer
How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
Corey Schafer
Easily Resize Multiple Images Using Picasa
Corey Schafer
Easily Resize Multiple Images Using the Mac Terminal
Corey Schafer
Python Tutorial: virtualenv and why you should use virtual environments
Corey Schafer
Python Tutorial: pip - An in-depth look at the package management system
Corey Schafer
Git Tutorial: Using the Stash Command
Corey Schafer
How Software Engineers, Developers, and Designers can volunteer their skills
Corey Schafer
Git Tutorial: Diff and Merge Tools
Corey Schafer
Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Corey Schafer
Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Corey Schafer
Python Tutorial: str() vs repr()
Corey Schafer
Programming Terms: DRY (Don't Repeat Yourself)
Corey Schafer
Programming Terms: String Interpolation
Corey Schafer
Programming Terms: Idempotence
Corey Schafer
Python Tutorial: Namedtuple - When and why should you use namedtuples?
Corey Schafer
Programming Terms: Mutable vs Immutable
Corey Schafer
Python Tutorial: Else Clauses on Loops
Corey Schafer
Overview of Online Learning Resources
Corey Schafer
Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Corey Schafer
Git Tutorial for Beginners: Command-Line Fundamentals
Corey Schafer
Quickest and Easiest Way to Run a Local Web-Server
Corey Schafer
Python Tutorial: Generators - How to use them and the benefits you receive
Corey Schafer
Python Tutorial: Comprehensions - How they work and why you should be using them
Corey Schafer
Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Corey Schafer
Programming Terms: Combinations and Permutations
Corey Schafer
Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Corey Schafer
Preparing for a Python Interview: 10 Things You Should Know
Corey Schafer
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
Corey Schafer
SQL Tutorial for Beginners 2: Creating Your First Table
Corey Schafer
SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
Corey Schafer
Linux/Mac Terminal Tutorial: Navigating your Filesystem
Corey Schafer
Python: Ex Machina Easter Egg - Hidden Message within the Code
Corey Schafer
Mac Tip: New Split Screen Feature in El Capitan
Corey Schafer
Setting up a Python Development Environment in Eclipse
Corey Schafer
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Corey Schafer
SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
Corey Schafer
More on: Tool Use & Function Calling
View skill →
🎓
Tutor Explanation
DeepCamp AI