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
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1
00:00:00,000 --> 00:00:05,060
[MUSIC PLAYING]

2
00:00:05,060 --> 00:00:05,890
DOUG LLOYD: OK.

3
00:00:05,890 --> 00:00:08,680
So let's talk about how to
use the Linux command line.

4
00:00:08,680 --> 00:00:11,860
Now, the CS50 IDE, or in
fact, even a CS50 appliance,

5
00:00:11,860 --> 00:00:15,210
if you're familiar with that, or
you're taking an older version of CS50,

6
00:00:15,210 --> 00:00:17,420
is a cloud-based machine
which runs Ubuntu,

7
00:00:17,420 --> 00:00:20,259
which is one of the many flavors
of the Linux operating system.

8
00:00:20,259 --> 00:00:22,300
Linux operating system is
favored by programmers,

9
00:00:22,300 --> 00:00:25,690
because it's just cooler, right?

10
00:00:25,690 --> 00:00:29,170
Many modern Linux distributions
have graphical user interfaces,

11
00:00:29,170 --> 00:00:33,710
which we also call GUIs, G-U-I, to
allow easy mouse-based navigation,

12
00:00:33,710 --> 00:00:36,920
which you're probably familiar with,
if you're a Windows or Mac user,

13
00:00:36,920 --> 00:00:39,961
moving around your mouse,
double-clicking on icons, and so on.

14
00:00:39,961 --> 00:00:42,210
Still though, as a programmer,
and even though the IDE

15
00:00:42,210 --> 00:00:44,800
contains the ability to
do some graphical user

16
00:00:44,800 --> 00:00:47,400
stuff, clicking, and
dragging, and all that,

17
00:00:47,400 --> 00:00:50,197
you'll still be using your
terminal window pretty frequently.

18
00:00:50,197 --> 00:00:52,280
And you can do many of the
same tasks that you can

19
00:00:52,280 --> 00:00:53,905
do with a mouse with keyboard commands.

20
00:00:53,905 --> 00:00:56,821
And we're going to talk a little bit
about what some of those commands

21
00:00:56,821 --> 00:00:58,050
are right now.

22
00:00:58,050 --> 00:01:02,490
Now, these commands can be used
on any Unix-based operating

23
00:01:02,490 --> 00:01:06,790
system, which includes Linux,
but also includes Mac OS.

24
00:01:06,790 --> 00:01:12,930
If you open up Terminal on your Mac,
you can use these exact commands.

25
00:01:12,930 --> 00:01:15,705
Windows also has Command
Prompt, but some of the commands

26
00:01:15,705 --> 00:01:17,871
are slightly different, so
it doesn't actually work,

27
00:01:17,871 --> 00:01:20,080
because Windows is not
a Unix-based system.

28
00:01:20,080 --> 00:01:22,620
So let's take a look at some
of these Linux commands.

29
00:01:22,620 --> 00:01:26,100
The first one that you'll
probably use quite a lot is ls.

30
00:01:26,100 --> 00:01:30,410
That's a lowercase l, followed by a
lowercase s, which is short for list.

31
00:01:30,410 --> 00:01:33,720
And what the list command does is it
gives you a readout of all the files

32
00:01:33,720 --> 00:01:35,670
and folders in your current directory.

33
00:01:35,670 --> 00:01:39,430
So you can see everything you can
get to from where you currently are.

34
00:01:39,430 --> 00:01:41,545
So I've opened up here the CS50 IDE.

35
00:01:41,545 --> 00:01:44,540
And I'm going to zoom-in in a
second to give you a closer look,

36
00:01:44,540 --> 00:01:47,240
but here's the broad picture
of what the IDE looks like.

37
00:01:47,240 --> 00:01:49,580
On the left, you can see we have
a file tree, which you're probably

38
00:01:49,580 --> 00:01:52,663
familiar with, double-clicking, and
files and folders, and all that stuff.

39
00:01:52,663 --> 00:01:54,694
So that's still there
in the CS50 appliance.

40
00:01:54,694 --> 00:01:57,860
At the center in the top is where you're
going to be writing your code, once

41
00:01:57,860 --> 00:01:58,960
you click on a file.

42
00:01:58,960 --> 00:02:00,900
And at the bottom, we
have a terminal window,

43
00:02:00,900 --> 00:02:04,040
which is where we can execute
these terminal commands.

44
00:02:04,040 --> 00:02:07,460
I'm going to zoom-in
and head over here, just

45
00:02:07,460 --> 00:02:12,360
to show you that, in fact, I can
click on these files and folders.

46
00:02:12,360 --> 00:02:17,010
So clearly, where I currently am, I have
two folders, called pset0 and pset1,

47
00:02:17,010 --> 00:02:20,520
and three files, one called
hello, one called hello.c,

48
00:02:20,520 --> 00:02:22,870
and one called hello.txt.

49
00:02:22,870 --> 00:02:27,100
So let's move down to the terminal
window and get a closer look.

50
00:02:27,100 --> 00:02:31,010
So we just talked, again, about the
fact that we have three files and two

51
00:02:31,010 --> 00:02:32,970
folders in the current directory.

52
00:02:32,970 --> 00:02:37,080
If I type ls, which again
is the command to list

53
00:02:37,080 --> 00:02:40,870
the contents of the current
directory, and then I hit Enter,

54
00:02:40,870 --> 00:02:47,220
look what I see, hello, hello.c,
hello.txt, pset0 and pset1.

55
00:02:47,220 --> 00:02:49,620
pset0 and pset1 are
colored blue, to indicate

56
00:02:49,620 --> 00:02:52,420
to you that those are directories
that we could navigate into.

57
00:02:52,420 --> 00:02:54,503
And we'll learn a little
bit about how to navigate

58
00:02:54,503 --> 00:02:56,290
into directories in a minute.

59
00:02:56,290 --> 00:03:00,920
And every other thing is colored black,
if it's a text file or a source code

60
00:03:00,920 --> 00:03:03,590
file, and green, if
it's an executable file.

61
00:03:03,590 --> 00:03:06,367
So clearly, that means that I
could run a program called, hello.

62
00:03:06,367 --> 00:03:07,950
That's what the green one there means.

63
00:03:07,950 --> 00:03:10,080
But basically, typing the
ls command has allowed

64
00:03:10,080 --> 00:03:13,470
me to look at everything that exists
in my current directory, which

65
00:03:13,470 --> 00:03:17,940
matches what we see here, in the
graphical display of the same.

66
00:03:17,940 --> 00:03:19,940
The next command you'll
probably use quite a bit

67
00:03:19,940 --> 00:03:24,792
is cd, lowercase c, lowercase d,
which is short for change directory.

68
00:03:24,792 --> 00:03:27,500
This allows us to do what I was
talking about a second ago, which

69
00:03:27,500 --> 00:03:31,150
is to navigate between
directories at the command

70
00:03:31,150 --> 00:03:33,700
line, as opposed to
double-clicking on folders.

71
00:03:33,700 --> 00:03:37,250
So if we type cd and then
the name of a directory,

72
00:03:37,250 --> 00:03:40,890
we can get into that directory.

73
00:03:40,890 --> 00:03:44,680
As an aside, know that the name
of the current directory is always

74
00:03:44,680 --> 00:03:48,670
dot, and the name of the directory
one level above where we are now,

75
00:03:48,670 --> 00:03:54,820
that is the name of the folder in
which our folder is, dot, dot--

76
00:03:54,820 --> 00:03:56,851
or in which our folder is, is dot, dot.

77
00:03:56,851 --> 00:03:59,350
And if you're ever curious about
the name of your directory,

78
00:03:59,350 --> 00:04:03,430
you can type pwd, which stands
for present working directory.

79
00:04:03,430 --> 00:04:06,827
We'll take a look at all of these
now, by heading back to the CS50 IDE.

80
00:04:06,827 --> 00:04:08,160
So I'm back in my workspace now.

81
00:04:08,160 --> 00:04:11,930
And I'll zoom-in again on the
terminal, so we can take a look

82
00:04:11,930 --> 00:04:14,209
at moving around within the IDE.

83
00:04:14,209 --> 00:04:16,250
So I'm going to list the
contents of my directory

84
00:04:16,250 --> 00:04:19,220
again, just to reground
us in where we are.

85
00:04:19,220 --> 00:04:21,740
So if I type ls, which
is for list again,

86
00:04:21,740 --> 00:04:24,160
I see that I can get to pset0 and pset1.

87
00:04:24,160 --> 00:04:26,420
Those are the directories
I can get to from here.

88
00:04:26,420 --> 00:04:30,400
I know that, because the IDE gives
me a clue by coloring them blue.

89
00:04:30,400 --> 00:04:33,295
Let's say that I want to
get into my pset1 directory,

90
00:04:33,295 --> 00:04:35,310
because I'm working on problem set 1.

91
00:04:35,310 --> 00:04:41,380
I can type cd-- again, short for
change directory-- space, pset1.

92
00:04:41,380 --> 00:04:43,334
And if I hit Enter, notice what happens.

93
00:04:43,334 --> 00:04:45,000
It doesn't look like a lot has happened.

94
00:04:45,000 --> 00:04:50,510
But if you look at the prompt, it now
tells me that I'm in ~/workspace/pset1.

95
00:04:50,510 --> 00:04:55,510
I've navigated into the pset1
folder that was within my workspace.

96
00:04:55,510 --> 00:05:00,560
And if I type ls, I see some
different stuff here, right?

97
00:05:00,560 --> 00:05:03,810
This isn't the same
list that I saw before.

98
00:05:03,810 --> 00:05:05,350
I've navigated into pset1.

99
00:05:05,350 --> 00:05:08,560
And so now, when I type ls, I'm
getting the context of what can I

100
00:05:08,560 --> 00:05:12,600
see from within the pset1 folder.

101
00:05:12,600 --> 00:05:16,056
Now, I'm going to type control
l, which just clears the screen.

102
00:05:16,056 --> 00:05:18,180
And I'm going to list the
contents of the directory

103
00:05:18,180 --> 00:05:18,880
again, just so you can see.

104
00:05:18,880 --> 00:05:20,730
I just wanted to do that to
clear out some of the stuff

105
00:05:20,730 --> 00:05:22,521
that you saw down below
and to prevent this

106
00:05:22,521 --> 00:05:24,660
from going too far down out of range.

107
00:05:24,660 --> 00:05:28,440
Now, I said earlier that, if I want
to navigate to the current directory,

108
00:05:28,440 --> 00:05:31,580
I can type cd space dot.

109
00:05:31,580 --> 00:05:32,080
Hit Enter.

110
00:05:32,080 --> 00:05:33,330
It doesn't do anything, right?

111
00:05:33,330 --> 00:05:35,480
I'm changing directories
to the current directory.

112
00:05:35,480 --> 00:05:37,813
You're not always going to
find a need for a single dot,

113
00:05:37,813 --> 00:05:39,540
but you will occasionally.

114
00:05:39,540 --> 00:05:41,950
Let's say that I want
to move up one level.

115
00:05:41,950 --> 00:05:44,450
I want to get back to
my workspace directory.

116
00:05:44,450 --> 00:05:49,800
I can't type cd workspace,
there's no such file or directory.

117
00:05:49,800 --> 00:05:52,780
And the reason for that--
if I type ls one more time--

118
00:05:52,780 --> 00:05:58,060
is that there is no directory called
workspace inside of my pset1 directory.

119
00:05:58,060 --> 00:06:00,275
I'm going to clear my
screen again with control l.

120
00:06:00,275 --> 00:06:02,150
Remember what I said
earlier, though, that we

121
00:06:02,150 --> 00:06:04,010
can navigate back with dot, dot.

122
00:06:04,010 --> 00:06:05,880
That's the name of the parent directory.

123
00:06:05,880 --> 00:06:10,727
So if I type cd, space, dot,
dot, and then hit Enter,

124
00:06:10,727 --> 00:06:11,810
now look at what happened.

125
00:06:11,810 --> 00:06:15,250
My command prompt tells me that I'm
back in my ~/workspace directory.

126
00:06:15,250 --> 00:06:19,360
I moved up one level,
thanks to dot, dot.

127
00:06:19,360 --> 00:06:23,400
Now, let's say that I'm using an
operating system that is Linux-based,

128
00:06:23,400 --> 00:06:25,440
but doesn't necessarily
tell me where I am.

129
00:06:25,440 --> 00:06:28,370
This one happens to tell us that
I'm in ~/workspace right now,

130
00:06:28,370 --> 00:06:29,280
right at the prompt.

131
00:06:29,280 --> 00:06:31,940
But I could be completely
lost in a mess of folders,

132
00:06:31,940 --> 00:06:34,946
and I have no idea where I am and
no idea where I want to get back to.

133
00:06:34,946 --> 00:06:36,320
There's two things that I can do.

134
00:06:36,320 --> 00:06:40,920
First of all, I can figure
out where I am, by typing pwd.

135
00:06:40,920 --> 00:06:42,720
That's my present working directory.

136
00:06:42,720 --> 00:06:45,830
And if I hit Enter, it
tells me exactly where I am.

137
00:06:45,830 --> 00:06:49,400
Now /home/ubuntu is the
long way of saying, tilde,

138
00:06:49,400 --> 00:06:51,290
which is your home directory.

139
00:06:51,290 --> 00:06:56,540
But it tells me that I'm in
home/ubuntu/workspace, or ~/workspace.

140
00:06:56,540 --> 00:07:00,700
I'm going to navigate to
my pset1 directory again,

141
00:07:00,700 --> 00:07:02,229
and I'm going to list the contents.

142
00:07:02,229 --> 00:07:04,770
And I see that I have another
directory there, called extras.

143
00:07:04,770 --> 00:07:09,020
So I'm going to cd into extras, and
then I'm going to clear my screen.

144
00:07:09,020 --> 00:07:11,540
So now, I'm pretty far in, right?

145
00:07:11,540 --> 00:07:13,680
What if I want to back
to workspace immediately?

146
00:07:13,680 --> 00:07:15,138
There's a couple things I could do.

147
00:07:15,138 --> 00:07:18,750
I could type cd, dot, dot, slash, dot,
dot, to move up one level and then

148
00:07:18,750 --> 00:07:19,640
another level.

149
00:07:19,640 --> 00:07:21,090
But that's kind of annoying.

150
00:07:21,090 --> 00:07:24,990
So if I ever want to get back to
just my home directory, tilde,

151
00:07:24,990 --> 00:07:27,690
I can type cd with nothing after it.

152
00:07:27,690 --> 00:07:29,224
Cd, Enter.

153
00:07:29,224 --> 00:07:30,140
And now, I'm in tilde.

154
00:07:30,140 --> 00:07:34,310
And if I want to get to workspace,
I can just type cd workspace.

155
00:07:34,310 --> 00:07:36,770
And that's how you work
changing directories

156
00:07:36,770 --> 00:07:42,080
within the CS50 IDE or any Linux
operating system at the command line.

157
00:07:42,080 --> 00:07:42,580
All right.

158
00:07:42,580 --> 00:07:45,610
The next one that might
come in handy is mkdir,

159
00:07:45,610 --> 00:07:48,709
which is short for make a directory,
if I need to create a new folder.

160
00:07:48,709 --> 00:07:50,750
If you're familiar with
the GUI operating system,

161
00:07:50,750 --> 00:07:51,820
you might right-click.

162
00:07:51,820 --> 00:07:54,500
And then, when the context menu
pops up, choose New Folder.

163
00:07:54,500 --> 00:07:56,250
That's probably how
you've done it before.

164
00:07:56,250 --> 00:08:00,979
But we can also create
directories at the command line.

165
00:08:00,979 --> 00:08:02,020
So we're back in the IDE.

166
00:08:02,020 --> 00:08:08,020
I'll zoom-in on the terminal and
list the contents of my directory

167
00:08:08,020 --> 00:08:11,882
again, just to give us
a frame of reference.

168
00:08:11,882 --> 00:08:14,340
Let's say that, now, I've
finished working on problem set 0

169
00:08:14,340 --> 00:08:15,580
and problem set 1.

170
00:08:15,580 --> 00:08:19,390
So I want to create a new directory
to work on for problem set 2.

171
00:08:19,390 --> 00:08:20,420
How do I do that?

172
00:08:20,420 --> 00:08:24,132
Well, again, I could right-click in the
left side there and choose New Folder

173
00:08:24,132 --> 00:08:25,340
and create a pset2 directory.

174
00:08:25,340 --> 00:08:26,240
That would work too.

175
00:08:26,240 --> 00:08:28,615
But then I also do it at the
command line pretty quickly,

176
00:08:28,615 --> 00:08:35,049
by typing mkdir, space-- I
typed in n, but-- space pset2.

177
00:08:35,049 --> 00:08:38,659
If I hit Enter and then I list the
contents of my directory again,

178
00:08:38,659 --> 00:08:40,710
I see that, look, now
I have a pset2 folder.

179
00:08:40,710 --> 00:08:43,110
And I can navigate into
that using cd and do

180
00:08:43,110 --> 00:08:45,614
all the work I need to do for pset2.

181
00:08:45,614 --> 00:08:48,530
Incidentally, I'll just pop over
here really quickly to the file tree.

182
00:08:48,530 --> 00:08:53,494
And you can see that, also, in
the graphical File Explorer,

183
00:08:53,494 --> 00:08:56,160
we can see that the pset2 directory
has also been created there.

184
00:08:56,160 --> 00:08:58,537
And I can navigate to it,
using the GUI as well.

185
00:08:58,537 --> 00:09:00,870
The next time and that's
probably going to come in handy

186
00:09:00,870 --> 00:09:03,650
is cp, which is short for copy.

187
00:09:03,650 --> 00:09:06,960
Copy, unlike all the other
commands we've seen before,

188
00:09:06,960 --> 00:09:11,800
takes two arguments, a source, the
name of the file that you want to copy,

189
00:09:11,800 --> 00:09:15,810
and a destination, where you
want to copy the file to.

190
00:09:15,810 --> 00:09:19,490
It's pretty easy to copy
a file, so let's do that.

191
00:09:19,490 --> 00:09:20,640
So we're back in the IDE.

192
00:09:20,640 --> 00:09:24,540
I'm going to list the contents
of my current directory with ls.

193
00:09:24,540 --> 00:09:28,310
Now, let's say that I want
to make a copy of hello.txt.

194
00:09:28,310 --> 00:09:32,120
Again, from the file tree on the
left, the graphical interface,

195
00:09:32,120 --> 00:09:35,969
I could right-click on hello.txt,
make a copy, paste the copy.

196
00:09:35,969 --> 00:09:38,260
But I can do it pretty quickly
at the command line too.

197
00:09:38,260 --> 00:09:42,520
Let's say I want to copy
hello.txt to hi.txt.

198
00:09:42,520 --> 00:09:45,850
I can cp, space, hello.txt.

199
00:09:45,850 --> 00:09:48,850
That's my source file, so that's why
I'm going to choose that one first.

200
00:09:48,850 --> 00:09:51,058
And then I need to name the
destination file, hi.txt.

201
00:09:51,058 --> 00:09:53,690


202
00:09:53,690 --> 00:09:54,620
I hit Enter.

203
00:09:54,620 --> 00:09:57,930
And if I list the contents of my
directory again, there's hi.txt.

204
00:09:57,930 --> 00:09:59,220
I made a copy of it.

205
00:09:59,220 --> 00:10:01,090
And in fact, if I went
into hi.txt, I could

206
00:10:01,090 --> 00:10:04,030
see that it would be an exact
duplicate of everything that

207
00:10:04,030 --> 00:10:08,330
existed in my hello.txt file.

208
00:10:08,330 --> 00:10:09,790
So that's how you copy a file.

209
00:10:09,790 --> 00:10:12,680
But what if you want to
copy an entire directory?

210
00:10:12,680 --> 00:10:16,510
So for a second, let's take a look
at what's in my pset0 directory.

211
00:10:16,510 --> 00:10:23,950
If I cd pset0 and list the contents,
I have a directory called, sample,

212
00:10:23,950 --> 00:10:26,252
and a scratch file, scratch.sb2.

213
00:10:26,252 --> 00:10:27,210
So that's good to know.

214
00:10:27,210 --> 00:10:29,800
So let's clear the screen,
and I'm going to go back

215
00:10:29,800 --> 00:10:32,870
to my workspace directory for a second.

216
00:10:32,870 --> 00:10:36,630
Let's say that, now, I want to
make a copy of my pset0 directory.

217
00:10:36,630 --> 00:10:42,940
I can't just say cp pset0
pset3, for instance.

218
00:10:42,940 --> 00:10:46,220
You get this weird message,
omitting directory pset0.

219
00:10:46,220 --> 00:10:47,439
Why do you get that message?

220
00:10:47,439 --> 00:10:49,730
Well, it turns out that, when
you have a directory that

221
00:10:49,730 --> 00:10:53,150
has other stuff inside of it,
the cp command doesn't really

222
00:10:53,150 --> 00:10:55,590
necessarily know what to do with it.

223
00:10:55,590 --> 00:10:59,670
We need to explicitly
tell Linux, the terminal,

224
00:10:59,670 --> 00:11:03,720
I want you to copy the
pset0 directory and copy

225
00:11:03,720 --> 00:11:07,530
every folder that exists inside
of it and every file that

226
00:11:07,530 --> 00:11:08,750
exists inside of it.

227
00:11:08,750 --> 00:11:13,270
In other words, I need you to
recursively dive down into pset0

228
00:11:13,270 --> 00:11:15,660
and make a copy of everything in there.

229
00:11:15,660 --> 00:11:25,280
If I want to do that, what I can do
is cp-r, for recursive, pset0 pset3.

230
00:11:25,280 --> 00:11:26,850
Hit Enter.

231
00:11:26,850 --> 00:11:29,290
Now, if I list the
contents of my directory,

232
00:11:29,290 --> 00:11:32,180
I see there's the pset3
directory that I can work with.

233
00:11:32,180 --> 00:11:36,990
And if I cd into pset3 now and
then list the contents, look,

234
00:11:36,990 --> 00:11:39,594
there's sample and scratch.sb2 again.

235
00:11:39,594 --> 00:11:40,510
So that's pretty cool.

236
00:11:40,510 --> 00:11:43,819
So that's how you can copy an entire
directory, and not just a single file.

237
00:11:43,819 --> 00:11:45,860
So if you want to copy a
directory, just remember

238
00:11:45,860 --> 00:11:49,830
to use the -r flag when you're
working with the cp command.

239
00:11:49,830 --> 00:11:50,330
All right.

240
00:11:50,330 --> 00:11:52,320
So I've copied a file, but
I've done it by mistake.

241
00:11:52,320 --> 00:11:53,695
And now, I want to get rid of it.

242
00:11:53,695 --> 00:11:54,850
How do I do that?

243
00:11:54,850 --> 00:11:56,830
Again, if you're familiar
with a GUI interface,

244
00:11:56,830 --> 00:11:58,310
you can right-click
and just choose Delete.

245
00:11:58,310 --> 00:12:00,630
And it'll send it to the
trash or the Recycle Bin.

246
00:12:00,630 --> 00:12:03,320
But at the command line, we
can just type rm, for remove,

247
00:12:03,320 --> 00:12:05,580
and then the name of the
file we want to get rid of.

248
00:12:05,580 --> 00:12:08,614
Now, rm is very careful.

249
00:12:08,614 --> 00:12:11,280
It does a lot of double-checking,
to make sure that you actually

250
00:12:11,280 --> 00:12:12,377
want to delete the file.

251
00:12:12,377 --> 00:12:15,460
It doesn't want to make any mistakes,
because there's no Recycle Bin here.

252
00:12:15,460 --> 00:12:17,010
Once we delete a file, it's gone.

253
00:12:17,010 --> 00:12:18,710
And there's really no way to recover it.

254
00:12:18,710 --> 00:12:20,730
So we need to be pretty
careful, and so rm

255
00:12:20,730 --> 00:12:23,110
is going to be really careful for us.

256
00:12:23,110 --> 00:12:27,120
So let's go back to the IDE
and get rid of that hi.txt file

257
00:12:27,120 --> 00:12:29,640
that I created a minute ago with copy.

258
00:12:29,640 --> 00:12:30,560
So we're in the IDE.

259
00:12:30,560 --> 00:12:33,180
And I list the contents of my directory
again, just to give us some context.

260
00:12:33,180 --> 00:12:36,500
I mean, you can see that there's hi.txt,
which I created a little while ago.

261
00:12:36,500 --> 00:12:38,196
Now, I want to get rid of it.

262
00:12:38,196 --> 00:12:38,820
How do I do it?

263
00:12:38,820 --> 00:12:39,810
Again, just rm.

264
00:12:39,810 --> 00:12:46,220
So I can type rm hi.txt and hit Enter.

265
00:12:46,220 --> 00:12:47,970
And there's rm being
really careful for us

266
00:12:47,970 --> 00:12:50,178
and making sure we actually
want to delete this file.

267
00:12:50,178 --> 00:12:52,784
Do you really want to remove
regular empty file hi.txt?

268
00:12:52,784 --> 00:12:55,200
That's just like an operating
system, like Windows or Mac,

269
00:12:55,200 --> 00:12:56,310
that you might be
familiar with popping up

270
00:12:56,310 --> 00:12:58,770
that box says are you really
sure you want to do this.

271
00:12:58,770 --> 00:13:01,228
I'm pretty sure I want to this,
so I'm going to type, yes--

272
00:13:01,228 --> 00:13:04,390
or I could also just
type y-- and hit Enter.

273
00:13:04,390 --> 00:13:08,620
And if I list the contents of my
directory again, hi.txt is gone.

274
00:13:08,620 --> 00:13:10,000
Not bad, right?

275
00:13:10,000 --> 00:13:12,410
Let's press Control L, just
to get rid of all this stuff

276
00:13:12,410 --> 00:13:14,900
and get us back at
the top of the screen.

277
00:13:14,900 --> 00:13:18,520
Now, there is a way to
short circuit rm, so

278
00:13:18,520 --> 00:13:20,090
that it doesn't ask us that question.

279
00:13:20,090 --> 00:13:22,060
We really know we want
to get rid of that file,

280
00:13:22,060 --> 00:13:23,490
and we don't even want
to be asked the question.

281
00:13:23,490 --> 00:13:24,720
How do we do that?

282
00:13:24,720 --> 00:13:27,180
Well, we can specify an
extra flag, just like we

283
00:13:27,180 --> 00:13:30,400
did with cp where we
could add the -r flag,

284
00:13:30,400 --> 00:13:32,800
to recursively copy into a directory.

285
00:13:32,800 --> 00:13:35,630
There's another flag
for rm, which is -f,

286
00:13:35,630 --> 00:13:39,470
which is to force rm to do exactly
what we're telling it to do.

287
00:13:39,470 --> 00:13:44,610
So let's say that, now, I want
to get rid of my hello.txt file.

288
00:13:44,610 --> 00:13:46,490
I don't want that one either.

289
00:13:46,490 --> 00:13:47,370
What can I do?

290
00:13:47,370 --> 00:13:54,710
Well, I can rm -f hello.txt.

291
00:13:54,710 --> 00:13:57,530
What do you think is
going to happen here?

292
00:13:57,530 --> 00:13:58,030
It's gone.

293
00:13:58,030 --> 00:13:59,363
Didn't even ask me the question.

294
00:13:59,363 --> 00:14:03,600
And in fact, if I list the contents
of my directory again, it's gone.

295
00:14:03,600 --> 00:14:05,750
There's no undo here.

296
00:14:05,750 --> 00:14:09,554
hello.txt is gone, and I wasn't
even asked if I wanted to delete it.

297
00:14:09,554 --> 00:14:11,595
What if I want to get rid
of an entire directory?

298
00:14:11,595 --> 00:14:14,180


299
00:14:14,180 --> 00:14:17,039
The way you do that is
very similar to copy.

300
00:14:17,039 --> 00:14:19,080
If you want to delete a
directory, you don't just

301
00:14:19,080 --> 00:14:22,121
want to delete the directory, you want
to delete everything inside of it.

302
00:14:22,121 --> 00:14:26,250
And so you use -r, to
recursively delete a directory.

303
00:14:26,250 --> 00:14:28,600
So let's rm -r pset2.

304
00:14:28,600 --> 00:14:31,870
I'm not actually working on pset2,
so I can get rid of that directory.

305
00:14:31,870 --> 00:14:33,040
I hit Enter.

306
00:14:33,040 --> 00:14:35,050
Do I want to remove
the directory, pset2?

307
00:14:35,050 --> 00:14:37,160
Yes, I do.

308
00:14:37,160 --> 00:14:41,150
And if I list the contents of
my directory again, it's gone.

309
00:14:41,150 --> 00:14:41,650
All right?

310
00:14:41,650 --> 00:14:43,739
One more variation on this theme.

311
00:14:43,739 --> 00:14:46,280
So I'll clear the screen again,
to put everything at the top.

312
00:14:46,280 --> 00:14:47,420
Hit ls.

313
00:14:47,420 --> 00:14:49,890
Now, I want to get rid
of my pset3 directory,

314
00:14:49,890 --> 00:14:52,810
and I really know I want to
get rid of my pset3 directory.

315
00:14:52,810 --> 00:15:00,120
I can recursively and forcibly
remove my pset3 directory.

316
00:15:00,120 --> 00:15:03,900
Now, you're going to be really
careful when you're using rm -rf.

317
00:15:03,900 --> 00:15:06,784
As you program more, it'll be
something you just do really quickly.

318
00:15:06,784 --> 00:15:08,200
And in fact, I do it all the time.

319
00:15:08,200 --> 00:15:10,380
But it can lead to some
disastrous consequences,

320
00:15:10,380 --> 00:15:12,340
if you accidentally
delete the wrong thing.

321
00:15:12,340 --> 00:15:15,089
So I want you to be aware that
this is an option available to you,

322
00:15:15,089 --> 00:15:17,220
but use it sparingly,
and use it with caution.

323
00:15:17,220 --> 00:15:20,910
I know for a fact I'm not working
on my problem set 3 anymore, so I'm

324
00:15:20,910 --> 00:15:22,550
going to get rid of all of those files.

325
00:15:22,550 --> 00:15:26,420
And I know I don't want to be asked
every single time if I want to delete

326
00:15:26,420 --> 00:15:30,640
a file, so I'm going to rm -rf pset3.

327
00:15:30,640 --> 00:15:32,640
Didn't even ask me if I
wanted to get rid of it.

328
00:15:32,640 --> 00:15:33,840
I hit ls.

329
00:15:33,840 --> 00:15:35,680
pset3 is gone.

330
00:15:35,680 --> 00:15:39,730
So that's all the variations that you
can use to get rid of files with rm.

331
00:15:39,730 --> 00:15:43,620
The last command line command that's
going to pretty useful for you

332
00:15:43,620 --> 00:15:46,391
is mv, which is short for move.

333
00:15:46,391 --> 00:15:48,960
Move Is basically equivalent to rename.

334
00:15:48,960 --> 00:15:53,870
It moves a file from one location to
another, the source to the destination.

335
00:15:53,870 --> 00:15:59,400
Let's see where using a move might
be handy at the terminal window.

336
00:15:59,400 --> 00:16:02,070
So I'm in my pset1
directory, and I've noticed

337
00:16:02,070 --> 00:16:03,860
something has gone a little wrong.

338
00:16:03,860 --> 00:16:08,620
I was working on my greedy problem,
but I accidentally named it greddy.

339
00:16:08,620 --> 00:16:11,380
So when I try and run it through
check50, it doesn't really work.

340
00:16:11,380 --> 00:16:12,630
I do have a couple of options.

341
00:16:12,630 --> 00:16:16,220
We could do what we've done before,
which is to make a copy of the file.

342
00:16:16,220 --> 00:16:23,960
I could copy greddy.c
to greedy.c, right?

343
00:16:23,960 --> 00:16:25,580
Hit Enter.

344
00:16:25,580 --> 00:16:28,180
I see that both files are there.

345
00:16:28,180 --> 00:16:36,337
And then I could rm,
to remove, greddy.c.

346
00:16:36,337 --> 00:16:37,170
That gets rid of it.

347
00:16:37,170 --> 00:16:40,920
So that would work, after I confirm
that I want to get rid of it.

348
00:16:40,920 --> 00:16:44,770
And I effectively have
renamed greddy.c to greedy.c.

349
00:16:44,770 --> 00:16:48,460
I copied it, and then
removed the original.

350
00:16:48,460 --> 00:16:50,170
But that's a multi-step process.

351
00:16:50,170 --> 00:16:51,670
And certainly, there's a better way.

352
00:16:51,670 --> 00:16:52,420
In fact, there is.

353
00:16:52,420 --> 00:16:55,810
So let's hit Control L,
just to bring this back up,

354
00:16:55,810 --> 00:16:58,680
and list the contents
of my directory again.

355
00:16:58,680 --> 00:17:00,350
So let's say, oh, I made a mistake.

356
00:17:00,350 --> 00:17:03,470
I actually really did want
to call that file greddy.c.

357
00:17:03,470 --> 00:17:11,369
In one fell swoop, I can type
move greedy.c to greddy.c.

358
00:17:11,369 --> 00:17:12,470
Hit Enter.

359
00:17:12,470 --> 00:17:15,210
And now, I didn't have
to copy and remove it,

360
00:17:15,210 --> 00:17:16,880
I just was able to rename it.

361
00:17:16,880 --> 00:17:18,710
One-stop shopping.

362
00:17:18,710 --> 00:17:21,160
Now, there are a lot of other
basic command line utilities

363
00:17:21,160 --> 00:17:22,640
that you can use with
the Linux command line.

364
00:17:22,640 --> 00:17:24,990
And we'll be discussing a lot
of them in the future in CS50.

365
00:17:24,990 --> 00:17:27,948
But for now, just getting your feet
wet with working with this terminal

366
00:17:27,948 --> 00:17:30,540
environment, these five commands
should get you pretty far

367
00:17:30,540 --> 00:17:34,990
in navigating around and
working with files in your IDE

368
00:17:34,990 --> 00:17:37,770
or in whatever Linux-based
operating system you're using.

369
00:17:37,770 --> 00:17:40,580
If you're curious and you want to
look ahead a little bit at some

370
00:17:40,580 --> 00:17:43,420
of the command line commands
we'll be using in the future,

371
00:17:43,420 --> 00:17:46,930
here's a list of a couple
of the more common ones.

372
00:17:46,930 --> 00:17:47,820
I'm Doug Lloyd.

373
00:17:47,820 --> 00:17:49,860
This is CS50.

374
00:17:49,860 --> 00:17:52,598