Moving a File from One Folder to Another Using Mac Terminal

In this article. you will see how to move a file from one folder to another without using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

 

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to move file1.txt from the folder “junk” to “junk1” in my “Desktop”.

First ‘cd’ into your source folder. In this case, its the “junk” folder. Now, here is how you can do the copy :

:junk admin$ mv file1.txt ../junk1

As you can see, we are using the ‘mv’ command. The ‘../’ pattern will point to the parent path of the current working directory.

Now you can list the contents of the folder “junk”.

:junk admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

Here you can see that the file, “file1.txt” is not there in the “junk” folder now.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

From this, you can see that the file is moved to your destination folder.

Copying Files from One Folder to Another without Using Path in Mac Terminal

In this article. you will see how to copy a file from one folder to another without using path in Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1” in my “Desktop”.

First ‘cd’ into your source folder. In this case, its the “junk” folder. Now, here is how you can do the copy :

junk admin$ cp file1.txt ../junk1

As you can see, we are using the ‘cp’ command and not giving the full path of the destination folder. Rather, we are using the ‘../’ pattern to point to the parent path of the current working directory.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:24 file1.txt

From this, you can see that the file is copied to your destination folder.

Finding the Difference in Two Files using Mac Terminal

In this article. you will see how to find the difference between the contents of two files using Mac terminal.

For this, I have with me, two text files with names “file1” and “file2”. Now lets see what the contents of those files are. For this, we can use the ‘cat’ command.

$ cat file1.txt

File Content :

file1

content A

$ cat file2.txt

File Content :

file2

content B

New line in file2

Now here is how you can find the differences in the contents of those two files :

$ diff file1.txt file2.txt

3,4c3,5

< file1

< content A

> file2

> content B

> New line in file2

Here, in the result of the ‘diff’ command, you can see that the contents that are different corresponding to both the files are listed. First, it will list the difference in content of the first file we are giving as parameter. For better understanding, lets change the order of file arguments and see :

$ diff file2.txt file1.txt

3,5c3,4

< file2

< content B

< New line in file2

> file1

> content A

 

Here, you from the result, you can see that when we change the order of parameter, the order of differences displayed by the ‘diff’ command also changes.

 

 

Copying Files from One Folder to Another From Another Folder using Mac Terminal

In this article. you will see how to copy a file from one folder to another while you are in an entirely different folder using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1” in my “Desktop”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1”. Here is how you can do this :

:Desktop admin$ cp /Users/admin/Desktop/junk/file1.txt /Users/admin/Desktop/junk1

As you can see, we are using the ‘cp’ command and giving the full path of both the source file and the  destination folder.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:20 file1.txt

From this, you can see that the file is copied to your destination folder.

Comparing Two Files using Mac Terminal

In this article. you will see how to compare two files to see whether there is any difference between two files using Mac terminal.

For this, I have with me, two text files with names “file1” and “file2”. Now lets see what the contents of those files are. For this, we can use the ‘cat’ command.

$ cat file1.txt

file1

$ cat file2.txt

file2

As you can see, the contents of files ‘file1.txt’ and ‘file2.txt’ are “file1” and “file2” respectively. Now here is how we can compare those two files :

$ cmp file1.txt file2.txt

file1.txt file2.txt differ: char 5, line 1

Here, in the result of the ‘cmp’ command, you can see that the compared files are showing one difference and that difference is in line 1, character 5. Now if you look at the contents of the file, you can see that it is true.

Copying Files from One Folder to Another using Mac Terminal

In this article. you will see how to copy a file from one folder to another using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1”. Here is how you can do this :

:junk admin$ cp file1.txt  /Users/admin/Desktop/Desktop\ v\ 2.0/junk1

As you can see, we are using the ‘cp’ command and giving the full path of the destination folder. Another thing you should note is that we are in the source folder so we can give the file name itself.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:13 file1.txt

From this, you can see that the file is copied to your destination folder.

How to List Files of a Folder without cd-ing in Mac Terminal

Normally, if you want to list the contents of a folder, you will have to ‘cd’ into that folder and then use the ‘ls’ command to list the files inside. But there is another way in which you can list the contents of a folder without ‘cd’-ing into that folder. Here is how you can do it.

ls /Users

And the result will look like this :

Guest Shared admin

Now if you want to use the detail listing command, it will look like this with the result :

ls -l /Users

total 0

drwxr-xr-x+ 11 201         _guest   374 Oct 15  2012 Guest

drwxrwxrwt  12 root        wheel    408 Oct 24 19:38 Shared

drwxr-xr-x@ 79 admin       staff   2686 Nov 24 11:51 admin

In these commands, what you are doing is that you are passing the folder name whose contents list you want to get along with your ‘ls’ command.

How to List Files with Permission Flags in Mac Terminal

Inorder to list the files of a directory with its details, you will use the following command in Mac terminal after pointing to the folder you want to check.

$ ls -l

And you will get the result like this :

total 24

-rw-r–r–  1 admin  staff   35 Sep 18 16:58 dirlistgen.txt

-rw-r–r–  1 admin  staff  112 Sep 19 09:59 listofcommandstoexecute.txt

-rw-r–r–  1 admin  staff   38 Sep 19 09:35 testfile.txt

Now, here is how you can list the files of a directory with its permission flags visible in terminal.

$ ls -io

And you will get the result like this :

total 24

79075397 -rw-r–r–  1 admin   35 Sep 18 16:58 dirlistgen.txt

79076264 -rw-r–r–  1 admin  112 Sep 19 09:59 listofcommandstoexecute.txt

79076347 -rw-r–r–  1 admin   38 Sep 19 09:35 testfile.txt

As you can see, this command will display the permission flags first followed by the remaining details provided by the ‘ls -l’ command.

Overriding in Swift programming

This article is a continuation from previous article

A subclass can provide its own custom implementation of an instance method, class method, instance property, class property, or subscript that it would otherwise inherit from a superclass. This is known as overriding.
When you provide a method, property, or subscript override for a subclass, it is sometimes useful to use the existing superclass implementation as part of your override. For example, you can refine the behavior of that existing implementation, or store a modified value in an existing inherited variable.

Overriding Methods:

You can override an inherited instance or class method to provide a tailored or alternative implementation of the method within your subclass.

The following example defines a new subclass of Vehicle called Train, which overrides the makeNoise method that Train inherits from Vehicle:

class Train: Vehicle {
    override func makeNoise() {
        println("Choo Choo")
    }
}

If you create a new instance of Train and call its makeNoise method, you can see that the Train subclass version of the method is called:

let train = Train()
train.makeNoise()
// prints "Choo Choo"

Overriding Properties:

You can override an inherited instance or class property to provide your own custom getter and setter for that property, or to add property observers to enable the overriding property to observe when the underlying property value changes.

Overriding Property Observers:

You can use property overriding to add property observers to an inherited property. This enables you to be notified when the value of an inherited property changes, regardless of how that property was originally implemented.