Skip to content

Commit

Permalink
Merge pull request JaiMaaSheeravali#33 from JaiMaaSheeravali/modify-t…
Browse files Browse the repository at this point in the history
…utorial

Tutorial Content Improved
  • Loading branch information
guptaprakhariitr committed May 13, 2021
2 parents 988b4a3 + 0761212 commit e67ad25
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void print_input_format()
// Print the current working directory of user
char cwd[100];

cout << GREEN;
cout << ":" << GREEN;
if (getcwd(cwd, sizeof(cwd)) != NULL)
cout << cwd;
else
Expand Down
82 changes: 54 additions & 28 deletions src/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int create_tutorial_folder()
struct passwd *pw = getpwuid(getuid());
home = strdup(pw->pw_dir);
home_dir = home;
// roosh_launch("rm -rf " + home_dir + "/tutorial");
roosh_launch("cp -r tutorial " + home_dir);
return 0;
}
Expand Down Expand Up @@ -113,14 +114,11 @@ int roosh_exec_tutorial(char **args, int num_args)
}
}

void printcommand(string line, int width)
{
const char separator = ' ';
cout << " " << left << setw(width) << setfill(separator) << line;
}
void write_tutorial(string filepath)

bool write_tutorial(string filepath)
{
string line;
filepath = home_dir+"/tutorial/tutorial_cmd/"+filepath;

ifstream myfile(filepath);

Expand All @@ -131,10 +129,10 @@ void write_tutorial(string filepath)
string cmd_path = home_dir + "/tutorial/tutorial_cmd/" + line + ".txt";
ifstream filename(cmd_path);
cout << MAGENTA;
printcommand(line, 60);
cout << "\t" << line << "\t\t"; //60
cout << RESET;
getline(myfile, line);
printcommand(line, 88);
cout << line << endl; //88
cout << endl;
cout << endl;
string cmd;
Expand All @@ -145,11 +143,10 @@ void write_tutorial(string filepath)
while (getline(filename, cmd))
{
cout << CYAN;
printcommand(cmd, 60);
cout << "\t" << cmd << endl;
getline(filename, cmd);
cout << RESET;
printcommand(cmd, 88);
cout << endl;
cout << "\t-> " << cmd << endl;
cout << endl;
}

Expand All @@ -160,38 +157,67 @@ void write_tutorial(string filepath)
cout << "-";
cout << endl;
cout << endl;

cout << "Please Enter 'q' to exit or any other key to continue: ";

string user_choice;
getline(cin, user_choice);

cout << endl;

if(user_choice == "q"){
myfile.close();
return true;
}
}
myfile.close();
}

else
cout << "Unable to open file";

return false;
}

int roosh_tutorial()
{
bool exit_tut = false;

cout << YELLOW << "\t\tWelcome to Roosh Tutorial!!!" << RESET << endl;
cout << endl;
cout << "\tOur Tutorial only provides a basic usage overview of most commonly used commands in linux." << endl;
cout << "\tTo know more about any command you can always use " << RED << "'man command'" << RESET << " in Roosh Input prompt." << endl;
cout << endl;
cout << "We have also provided certain test levels to test your understanding of tutorial content." << endl;
cout << "Levels can be accessed by using " << RED << "'tutorial level [level-number]'" << RESET << " command." << endl;
cout << "You have to find password hidden inside level and submit it using: \n\t" << RED << "'tutorial level [level-number] password'";
cout << RESET << " command and enterning the password." << endl;
cout << endl;
cout << endl;

cout << "Enter any key to continue or q to exit: ";

string user_choice;
getline(cin, user_choice);

if(user_choice == "q")
return 1;

cout << endl;

cout << "\n"
<< BLUE << " "
<< "Basic linux commands" << endl;
cout << RESET << endl;
write_tutorial(home_dir + "/tutorial/tutorial_cmd/basiccmdlist.txt");
exit_tut = write_tutorial("basiccmdlist.txt");

if(exit_tut)
return 1;

cout << BLUE << " "
<< "Intermediate linux commands" << endl;
<< "Git linux commands" << endl;
cout << RESET << endl;
write_tutorial(home_dir + "/tutorial/tutorial_cmd/intermediatecmdlist");
cout << MAGENTA << "pipes (|)" << RESET << " "
<< "to pass output of one command as intput to another" << endl;
cout << endl;
cout << MAGENTA << "Redirection" << RESET << endl;
cout << endl;
cout << "1.output redirection(<)"
<< " "
<< " to fetch output to a file" << endl;
cout << endl;
cout << "2.Input redirection(>)"
<< " "
<< " to take input from a file" << endl;
cout << endl;

exit_tut = write_tutorial("gitcmdlist.txt");

return 1;
}
6 changes: 6 additions & 0 deletions tutorial/tutorial_cmd/apt-get.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo apt-get update
Fetches and updates list of available linux packages (requires internet)
sudo apt-get install [Package-name]
Download (if required) and install the package in linux
sudo apt-get upgrade
Updates all outdated Installed packages in linux.
22 changes: 22 additions & 0 deletions tutorial/tutorial_cmd/basiccmdlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ ls
to list directory contents
man
display manual pages
sudo
Give admin Priviledges to process
apt-get
Used to install and update packages in linux (often requires sudo or root Priviledges)
mv
Move or rename files and directories
mkdir
Expand All @@ -12,3 +16,21 @@ rmdir
Removes a directory
touch
Change a file access and modification times
cat
Print and concatenate files
echo
Print given arguments
chmod
Change the access permissions of a file or directory
grep
Find patterns in files using regular expressions
wc
Used to count number of words or lines in a file
sort
Sort lines of text files
pipes
pass output of one command as intput to another
redirection
redirect output/input to or from a file respectively
misc
Miscellaneous useful Commands in linux
3 changes: 1 addition & 2 deletions tutorial/tutorial_cmd/cat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Concatenate several files into the target file
cat {{file1}} {{file2}} >> {{target_file}}
Append several files into the target file
cat -n {{file}}
Number all output lines:

Number all output lines:
10 changes: 4 additions & 6 deletions tutorial/tutorial_cmd/cd.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cd path/to/directory
command to Go to the given directory
cd
cd [path/to/directory]
command to Go to the given directory (either relative or absolute)
cd ~
command to go to home directory of current user
cd ..
Go up to the parent of the current directory
cd -
Go to the previously chosen directory
Go up to the parent of the current directory
3 changes: 1 addition & 2 deletions tutorial/tutorial_cmd/chmod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ give [o]thers (not in the file owner's group) the same rights as the [g]roup
chmod o= {{file}}
Remove all rights from [o]thers
chmod -R g+w,o+w {{directory}}
Change permissions recursively giving [g]roup and [o]thers the ability to [w]rite

Change permissions recursively giving [g]roup and [o]thers the ability to [w]rite
4 changes: 4 additions & 0 deletions tutorial/tutorial_cmd/cp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cp {{source}} {{target}}
Make a copy of file at source to target location
cp -r {{source}} {{target}}
Recursively copy a directory at source to target address.
7 changes: 1 addition & 6 deletions tutorial/tutorial_cmd/echo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ echo "{{Hello World}}"
Print a text message. Note: quotes are optional
echo "{{My path is $PATH}}"
Print a message with environment variables
echo -n "{{Hello World}}"
Print a message without the trailing newline
echo "{{Hello World}}" >> {{file.txt}}
Append a message to the file
echo -e "{{Column 1\tColumn 2}}"
Enable interpretation of backslash escapes (special characters):

Append a message to the file
29 changes: 1 addition & 28 deletions tutorial/tutorial_cmd/git.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
git config –global user.name “[name]”
sets the author name to be used with your commits
git config –global user.email “[email address]”
sets the email address to be used with your commits
git init [repository name]
to start a new repository
git clone [url]
to obtain a repository from an existing URL
git add [file]
adds a file to the staging area
git add *
adds one or more to the staging area.
git commit -m “[ Type in the commit message]”
records or snapshots the file permanently in the version history
git commit -a
commits any files you’ve added with the git add command and also commits any files you’ve changed since then
git diff –staged
shows the differences between the files in the staging area and the latest version present
git reset [file]
command unstages the file, but it preserves the file contents
git reset [commit]
command undoes all the commits after the specified commit and preserves the changes locally
git status
command lists all the files that have to be committed.
git log
Expand All @@ -32,12 +12,5 @@ git merge [branch name]
merges the specified branch’s history into the current branch.
git remote add [variable name] [Remote Server Link]
command is used to connect your local repository to the remote server
git push [variable name] master
sends the committed changes of master branch to your remote repository
git push [variable name] [branch]
command sends the branch commits to your remote repository
git push –all [variable name]
command pushes all branches to your remote repository
git pull [Repository Link]
command fetches and merges changes on the remote server to your working directory

command fetches and merges changes on the remote server to your working directory
6 changes: 6 additions & 0 deletions tutorial/tutorial_cmd/git_add.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git add [file]
adds a file to the staging area
git add [directory]
adds a directory to the staging area.
git add .
adds all files in current directory that are not staged
2 changes: 2 additions & 0 deletions tutorial/tutorial_cmd/git_clone.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git clone [url]
to obtain a repository from an existing URL (using ssh or https)
4 changes: 4 additions & 0 deletions tutorial/tutorial_cmd/git_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
git commit -m “[ Type in the commit message]”
records or snapshots the file permanently in the version history
git commit -a
commits any files you’ve added with the git add command and also commits any files you’ve changed since then
4 changes: 4 additions & 0 deletions tutorial/tutorial_cmd/git_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
git config -global user.name "[name]"
sets the author name to be used with commits
git config -global user.email "[email address]"
sets the email address to be used with your commits
2 changes: 2 additions & 0 deletions tutorial/tutorial_cmd/git_init.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git init [repository name]
Used to start a new git repository in the current directory
6 changes: 6 additions & 0 deletions tutorial/tutorial_cmd/git_push.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git push [remote repository name] master
sends the committed changes of master branch to your remote repository
git push [remote repository name] [branch]
command sends the branch commits to your remote repository
git push –all [remote repository name]
command pushes all branches to your remote repository
4 changes: 4 additions & 0 deletions tutorial/tutorial_cmd/git_reset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
git reset [file]
command unstages the file, but it preserves the file contents
git reset [commit]
command undoes all the commits after the specified commit and preserves the changes locally
16 changes: 16 additions & 0 deletions tutorial/tutorial_cmd/gitcmdlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
git_config
used while working with git
git_init
used to start a new repository
git_clone
clone a remote git repository
git_add
add file(s) to git staging area
git_commit
Commits a file and merges it in the current branch
git_reset
Used to undo changes
git_push
Pushes local commits to the remote repository
git
Miscellaneous git commands used for various purposes
3 changes: 1 addition & 2 deletions tutorial/tutorial_cmd/grep.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
grep "{{search_pattern}}" {{path/to/file}}
Search for a pattern within a file
grep --fixed-strings "{{exact_string}}" {{path/to/file}}
Search for an exact string (disables regular expressions)

Search for an exact string (disables regular expressions)
2 changes: 2 additions & 0 deletions tutorial/tutorial_cmd/init.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git init [repository name]
to start a new repository
14 changes: 0 additions & 14 deletions tutorial/tutorial_cmd/intermediatecmdlist

This file was deleted.

14 changes: 0 additions & 14 deletions tutorial/tutorial_cmd/intermediatecmdlist.txt

This file was deleted.

10 changes: 5 additions & 5 deletions tutorial/tutorial_cmd/ls.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ls
ls command is used to list directory contents
ls -1
List files one per line
List details of file in current directory
ls -a
List all files, including hidden files
ls -F
List all files, with trailing / added to directory names
ls -la
Long format list (permissions, ownership, size, and modification date) of all files
ls -f
List all files, with trailing '/' added to directory names
ls -alt
Long format list (permissions, ownership, size, and modification date) of all files (including hidden files)
Loading

0 comments on commit e67ad25

Please sign in to comment.